Class SortedObservableList<T>
- Namespace
- CarinaStudio.Collections
- Assembly
- CarinaStudio.AppBase.Core.dll
List which makes elements sorted automatically. Implementation of IList<T> are also optimized for sorted case.
public class SortedObservableList<T> : IList, ICollection, IList<T>, ICollection<T>, INotifyCollectionChanged, INotifyPropertyChanged, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
TType of element.
- Inheritance
-
SortedObservableList<T>
- Implements
-
IList<T>ICollection<T>IEnumerable<T>
- Inherited Members
- Extension Methods
Constructors
SortedObservableList(IComparer<T>, IEnumerable<T>?)
Initialize new SortedObservableList<T> instance.
public SortedObservableList(IComparer<T> comparer, IEnumerable<T>? elements = null)
Parameters
comparerIComparer<T>IComparer<T> to sort elements.
elementsIEnumerable<T>Initial elements.
SortedObservableList(IEnumerable<T>?)
Initialize new SortedObservableList<T> instance.
public SortedObservableList(IEnumerable<T>? elements = null)
Parameters
elementsIEnumerable<T>Initial elements.
SortedObservableList(Comparison<T>, IEnumerable<T>?)
Initialize new SortedObservableList<T> instance.
public SortedObservableList(Comparison<T> comparison, IEnumerable<T>? elements = null)
Parameters
comparisonComparison<T>Comparison<T> to sort elements.
elementsIEnumerable<T>Initial elements.
Properties
Capacity
Get capacity of the list.
public int Capacity { get; }
Property Value
Comparer
Get IComparer<T> used to compare elements by this list.
public IComparer<T> Comparer { get; }
Property Value
- IComparer<T>
Count
Get number of elements.
public int Count { get; }
Property Value
this[int]
Get element.
public T this[int index] { get; }
Parameters
indexintIndex of element.
Property Value
- T
Element.
Methods
Add(T)
Add element to list.
public int Add(T element)
Parameters
elementTElement to add.
Returns
- int
Index of added element in list.
AddAll(IEnumerable<T>, bool)
Add elements to list.
public void AddAll(IEnumerable<T> elements, bool isSorted = false)
Parameters
elementsIEnumerable<T>Elements to add.
isSortedboolWhether elements in
elementsare already sorted or not.
AsReadOnly()
Make the list as read-only IList<T>.
public IList<T> AsReadOnly()
Returns
- IList<T>
Read-only IList<T>, the instance also implements INotifyCollectionChanged and IReadOnlyList<T>.
Clear()
Clear all elements.
public void Clear()
Contains(T)
Check whether given element is contained in list or not.
public bool Contains(T element)
Parameters
elementTElement.
Returns
- bool
True if element is contained in list.
CopyTo(int, T[], int, int)
Copy elements to array.
public void CopyTo(int index, T[] array, int arrayIndex, int count)
Parameters
indexintIndex of first element in list to copy.
arrayT[]Array to place copied elements.
arrayIndexintIndex of first position in
arrayto place copied elements.countintNumber of elements to copy.
CopyTo(T[], int)
Copy elements to array.
public void CopyTo(T[] array, int arrayIndex)
Parameters
arrayT[]Array to place copied elements.
arrayIndexintIndex of first position in
arrayto place copied elements.
GetEnumerator()
Get IEnumerator<T> to enumerate elements.
public IEnumerator<T> GetEnumerator()
Returns
IndexOf(T)
Get index of given element in list.
public int IndexOf(T element)
Parameters
elementTElement.
Returns
- int
Index of element in list, or -1 if element is not contained in list.
IsEmpty()
Check whether the list is empty or not.
public bool IsEmpty()
Returns
- bool
True if the list is empty.
IsNotEmpty()
Check whether the list is not empty or not.
public bool IsNotEmpty()
Returns
- bool
True if the list is not empty.
Remove(T)
Remove first found of given element.
public bool Remove(T element)
Parameters
elementTElement to remove.
Returns
- bool
True if element has been removed.
RemoveAll(IEnumerable<T>, bool)
Remove elements from list.
public int RemoveAll(IEnumerable<T> elements, bool isSorted = false)
Parameters
elementsIEnumerable<T>Elements to remove.
isSortedboolWhether elements in
elementsare already sorted or not.
Returns
- int
Number of removed elements.
RemoveAll(Predicate<T>)
Remove elements which match given condition from list.
public int RemoveAll(Predicate<T> predicate)
Parameters
predicatePredicate<T>Function to check whether log matches given condition or not.
Returns
- int
Number of removed elements.
RemoveAt(int)
Remove element at given position.
public void RemoveAt(int index)
Parameters
indexintIndex of element to remove.
RemoveRange(int, int)
Remove elements.
public void RemoveRange(int index, int count)
Parameters
Reverse()
Make given list as reversed IList<T>.
public IList<T> Reverse()
Returns
- IList<T>
Reversed IList<T> which also implements INotifyCollectionChanged and IReadOnlyList<T>.
ReverseAsReadOnly()
Make given list as reversed and read-only IList<T>.
public IList<T> ReverseAsReadOnly()
Returns
- IList<T>
Reversed read-only IList<T> which also implements INotifyCollectionChanged and IReadOnlyList<T>.
Sort(T)
Move given element to correct position if needed.
public bool Sort(T element)
Parameters
elementTElement to move.
Returns
- bool
True if element has been moved to correct position.
SortAt(int)
Move given element to correct position if needed.
public bool SortAt(int index)
Parameters
indexintCurrent index of element to move.
Returns
- bool
True if element has been moved to correct position.
ToArray()
Copy elements to array.
public T[] ToArray()
Returns
- T[]
Array of copied elements
ToArray(int, int)
Copy elements to array.
public T[] ToArray(int index, int count)
Parameters
Returns
- T[]
Array of copied elements
TrimExcess()
Set the capacity to the actual number of elements in list.
public void TrimExcess()
Events
CollectionChanged
Raised when list changed.
public event NotifyCollectionChangedEventHandler? CollectionChanged
Event Type
PropertyChanged
Raised when property changed.
public event PropertyChangedEventHandler? PropertyChanged