Class MonitoredCollection<T>
- Namespace
- NanoByte.Common.Collections
- Assembly
- NanoByte.Common.dll
A collection that can easily be monitored for changes via events.
public class MonitoredCollection<T> : Collection<T>, IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
TThe type of elements in the collection.
- Inheritance
-
objectCollection<T>MonitoredCollection<T>
- Implements
-
IList<T>ICollection<T>IEnumerable<T>
- Inherited Members
- Extension Methods
Constructors
MonitoredCollection()
Creates a new monitored collection.
public MonitoredCollection()
MonitoredCollection(int)
Creates a new monitored collection with an upper limit to the number of elements.
public MonitoredCollection(int maxElements)
Parameters
maxElementsintThe maximum number of elements; 0 for no limit.
Properties
MaxElements
The maximum number of elements; 0 for no limit.
public int MaxElements { get; }
Property Value
Methods
AddMany(IEnumerable<T>)
Adds all the items in collection to the collection that weren't already there.
public void AddMany(IEnumerable<T> collection)
Parameters
collectionIEnumerable<T>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()
protected override void ClearItems()
InsertItem(int, T)
protected override void InsertItem(int index, T item)
Parameters
indexintitemT
RemoveItem(int)
protected override void RemoveItem(int index)
Parameters
indexint
SetItem(int, T)
protected override void SetItem(int index, T item)
Parameters
indexintitemT
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.
public void SetMany(IEnumerable<T> enumeration)
Parameters
enumerationIEnumerable<T>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.
public event Action<T>? Added
Event Type
- Action<T>
Changed
Occurs whenever something in the collection changes.
public event Action? Changed
Event Type
Removed
Occurs when an item has just been removed from the collection.
public event Action<T>? Removed
Event Type
- Action<T>
Removing
Occurs when an item is just about to be removed from the collection.
public event Action<T>? Removing
Event Type
- Action<T>