TrulyObservableOrderedSet<T>

References
An ordered set that notifies its subscribers whenever one of its INotifyPropertyChanged elements raises its PropertyChanged event.
Remarks: This class prevents the removal of elements by assemblies they cannot be edited by. At the time of removal, each element's IAssemblyRestrictedObject.Editable() method will be invoked, and if false, an InvalidOperationException will be thrown.
TA class that implements INotifyPropertyChanged as well as IAssemblyRestrictedObject where INotifyPropertyChanged, IAssemblyRestrictedObject

Constructors

TrulyObservableOrderedSet

#
public TrulyObservableOrderedSet(IEnumerable<T> items, IEqualityComparer<T> comparer = null)
Creates an instance with the given items.
items (IEnumerable<T>)Items that the instance will contain. If there are duplicate items, they will be removed.
comparer (IEqualityComparer<T> = null)custom comparerer, used to check for duplicates. If no comparer is specified, EqualityComparer<T>.Default is used.

TrulyObservableOrderedSet

#
public TrulyObservableOrderedSet(IEqualityComparer<T> comparer = null)
Creates an empty instance.
comparer (IEqualityComparer<T> = null)

Properties

Count

#
public int Count { get; }
Returns the total number of items in the set.

IsReadOnly

#
public bool IsReadOnly { get; }
Always returns false.

Indexers

this[]

#
public T this[int index] { get; set; }
Gets or replaces an element in the ordered set at the specified index.
index (int)The index of the element.
the element at the given index.
IndexOutOfRangeExceptionThrown if the index passed is out of bounds.
InvalidOperationExceptionThrown if the item that will be replaced at the specified index cannot be modified by the current assembly.

Methods

Add

#
public void Add(T item)
Adds an object to the end of the ordered set if the set does not already contain the item.
item (T)The item to add.

AddRange

#
public void AddRange(IEnumerable<T> items)
Add multiple objects to the end of the ordered set. Only distinct items are added. If new items were added, one CollectionChanged event is fired.
items (IEnumerable<T>)

Clear

#
public void Clear()
Clears the ordered set.
InvalidOperationExceptionThrown if at least one item currently in the set cannot be modified by the current assembly.

Contains

#
public bool Contains(T item)
Determines whether an element is in the set.
item (T)The item to check for inclusion.
True if the item is in the set; otherwise false.

CopyTo

#
public void CopyTo(T[] array, int arrayIndex)
Copies the values of the set to an array.
array (T[])The array to copy the values to.
arrayIndex (int)The index of the array to start the copy.

GetEnumerator

#
public IEnumerator<T> GetEnumerator()
Returns an enumerator that iterates through the set.

IndexOf

#
public int IndexOf(T item)
Searches for the specified object and returns the zero-based index of the first occurrence.
item (T)The item to locate.
The zero-based index of the first occurrence of item if found; otherwise -1.

Insert

#
public void Insert(int index, T item)
Inserts an element at the specified index.
index (int)The index to insert the element at.
item (T)The item to insert.
IndexOutOfRangeExceptionThrown if the index passed is out of bounds.

Remove

#
public bool Remove(T item)
Removes an element from the set.
item (T)The element to remove.
Returns true if the element was removed; otherwise returns false.
InvalidOperationExceptionThrown if the item that will be removed cannot be modified by the current assembly.

RemoveAt

#
public void RemoveAt(int index)
Removes an element at the specified index from the set.
index (int)The index of the element to remove.
IndexOutOfRangeExceptionThrown if the index passed is out of bounds.
InvalidOperationExceptionThrown if the item that will be removed cannot be modified by the current assembly.

RemoveRange

#
public bool RemoveRange(IEnumerable<T> items)
Remove a number of items. If at least one item was removed, one CollectionChanged event is fired.
items (IEnumerable<T>)
true if at least one item was removed

Sort<TKey>

#
public void Sort<TKey>(Func<T, TKey> keySelector, bool descending = false)
Sorts the set.
keySelector (Func<T, TKey>)
descending (bool = false)If true, the sort will happen in descending other; if false, it will happen in ascending order.
Explicit

IEnumerable.GetEnumerator

#
IEnumerator IEnumerable.GetEnumerator()
Returns an enumerator that iterates through the dictionary.

Events

CollectionChanged

#
public event NotifyCollectionChangedEventHandler CollectionChanged
Triggered whenever the set changes or when one of its elements has its PropertyChanged event triggered.