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
T
Type 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
comparer
IComparer<T>IComparer<T> to sort elements.
elements
IEnumerable<T>Initial elements.
SortedObservableList(IEnumerable<T>?)
Initialize new SortedObservableList<T> instance.
public SortedObservableList(IEnumerable<T>? elements = null)
Parameters
elements
IEnumerable<T>Initial elements.
SortedObservableList(Comparison<T>, IEnumerable<T>?)
Initialize new SortedObservableList<T> instance.
public SortedObservableList(Comparison<T> comparison, IEnumerable<T>? elements = null)
Parameters
comparison
Comparison<T>Comparison<T> to sort elements.
elements
IEnumerable<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
index
intIndex of element.
Property Value
- T
Element.
Methods
Add(T)
Add element to list.
public int Add(T element)
Parameters
element
TElement 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
elements
IEnumerable<T>Elements to add.
isSorted
boolWhether elements in
elements
are 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
element
TElement.
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
index
intIndex of first element in list to copy.
array
T[]Array to place copied elements.
arrayIndex
intIndex of first position in
array
to place copied elements.count
intNumber of elements to copy.
CopyTo(T[], int)
Copy elements to array.
public void CopyTo(T[] array, int arrayIndex)
Parameters
array
T[]Array to place copied elements.
arrayIndex
intIndex of first position in
array
to 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
element
TElement.
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
element
TElement 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
elements
IEnumerable<T>Elements to remove.
isSorted
boolWhether elements in
elements
are 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
predicate
Predicate<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
index
intIndex 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
element
TElement 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
index
intCurrent 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