Show / Hide Table of Contents

Class MonitoredCollection<T>

A collection that can easily be monitored for changes via events.

Inheritance
Object
MonitoredCollection<T>
Namespace: NanoByte.Common.Collections
Assembly: NanoByte.Common.dll
Syntax
public class MonitoredCollection<T> : Collection<T>
Type Parameters
Name Description
T

The type of elements in the collection.

Constructors

MonitoredCollection()

Creates a new monitored collection.

Declaration
public MonitoredCollection()

MonitoredCollection(Int32)

Creates a new monitored collection with an upper limit to the number of elements.

Declaration
public MonitoredCollection(int maxElements)
Parameters
Type Name Description
Int32 maxElements

The maximum number of elements; 0 for no limit.

Properties

MaxElements

The maximum number of elements; 0 for no limit.

Declaration
public int MaxElements { get; }
Property Value
Type Description
Int32

Methods

AddMany(IEnumerable<T>)

Adds all the items in collection to the collection that weren't already there.

Declaration
public void AddMany(IEnumerable<T> collection)
Parameters
Type Name Description
IEnumerable<T> collection

A collection of items to add to the collection.

Remarks

All events are raised en bloc after the items have been added.

After calling this method this collection will contain a superset of the items in collection, but not necessarily in the same order.

ClearItems()

Declaration
protected override void ClearItems()

InsertItem(Int32, T)

Declaration
protected override void InsertItem(int index, T item)
Parameters
Type Name Description
Int32 index
T item

RemoveItem(Int32)

Declaration
protected override void RemoveItem(int index)
Parameters
Type Name Description
Int32 index

SetItem(Int32, T)

Declaration
protected override void SetItem(int index, T item)
Parameters
Type Name Description
Int32 index
T item

SetMany(IEnumerable<T>)

Adds all the items in enumeration to the collection that weren't already there and removes all items in the collection that are not in enumeration.

Declaration
public void SetMany(IEnumerable<T> enumeration)
Parameters
Type Name Description
IEnumerable<T> enumeration

An enumeration with items to add to the collection.

Remarks

All events are raised en bloc after the items have been added.

After calling this method this collection will contain the same items as enumeration, but not necessarily in the same order.

Events

Added

Occurs when a new item has just been added to the collection.

Declaration
public event Action<T> Added
Event Type
Type Description
Action<T>

Changed

Occurs whenever something in the collection changes.

Declaration
public event Action Changed
Event Type
Type Description
Action

Removed

Occurs when an item has just been removed from the collection.

Declaration
public event Action<T> Removed
Event Type
Type Description
Action<T>

Removing

Occurs when an item is just about to be removed from the collection.

Declaration
public event Action<T> Removing
Event Type
Type Description
Action<T>

Extension Methods

UpdateUtils.To<TIn, TOut>(TIn, Func<TIn, TOut>)
JsonStorage.SaveJson<T>(T, Stream)
JsonStorage.SaveJson<T>(T, String)
JsonStorage.ToJsonString<T>(T)
JsonStorage.ReparseAsJson<T>(Object)
JsonStorage.ReparseAsJson<T>(Object, T)
XmlStorage.SaveXml(Object, Stream, String)
XmlStorage.SaveXml<T>(T, String, String)
XmlStorage.ToXmlString(Object, String)
ConversionUtils.ConvertToString<TType>(TType)
In This Article
Back to top Copyright Bastian Eicher