Class ObservableCollectionExtensions
- Namespace
- WindowSill.API
- Assembly
- WindowSill.API.dll
Provides extension methods for ObservableCollection<T>.
public static class ObservableCollectionExtensions
- Inheritance
-
ObservableCollectionExtensions
- Inherited Members
Methods
IndexOf<T>(ObservableCollection<T>, Predicate<T>)
Searches for the first element in the collection that matches the specified predicate and returns its index.
public static int IndexOf<T>(this ObservableCollection<T> collection, Predicate<T> predicate)
Parameters
collectionObservableCollection<T>The ObservableCollection<T> to search.
predicatePredicate<T>The Predicate<T> used to evaluate each element in the collection.
Returns
- int
The zero-based index of the first element that matches the predicate; otherwise, -1 if no matching element is found.
Type Parameters
T
SynchronizeWithAsync<T, U>(ObservableCollection<T>, IEnumerable<U>, Func<T, U, bool>?, Func<U, Task<T>>)
Synchronizes the contents of the ObservableCollection<T> with the specified collection of new items.
It essentially performs an incremental update to the origin collection based on the newItems.
public static Task SynchronizeWithAsync<T, U>(this ObservableCollection<T> origin, IEnumerable<U> newItems, Func<T, U, bool>? comparer, Func<U, Task<T>> convertToT)
Parameters
originObservableCollection<T>The ObservableCollection<T> to be synchronized.
newItemsIEnumerable<U>The collection of new items to synchronize with. If null, the
origincollection will be cleared.comparerFunc<T, U, bool>A function that compares items of type
Tfrom the original list with an item of typeUfrom the new list.convertToTFunc<U, Task<T>>A function that converts an item of type
Uto typeT.
Returns
Type Parameters
TThe type of elements in the ObservableCollection<T>.
UThe type of elements in the
newItemscollection.
Remarks
Note: This method is asynchronous and is not thread-safe.
This method performs the following operations to synchronize the origin collection:
- Removes items from
originthat are not present innewItems. - Moves items within
originto match the order ofnewItems. - Inserts new items from
newItemsintooriginat the appropriate positions.
origin and newItems is based on the Equals(object) method.
SynchronizeWith<T>(ObservableCollection<T>, IEnumerable<T>)
Updates the contents of the specified ObservableCollection<T> to match the items in the provided sequence.
It essentially performs an incremental update to the origin collection based on the newItems.
public static void SynchronizeWith<T>(this ObservableCollection<T> origin, IEnumerable<T> newItems)
Parameters
originObservableCollection<T>The ObservableCollection<T> to be updated.
newItemsIEnumerable<T>The sequence of items to synchronize with the collection.
Type Parameters
TThe type of elements in the collection.
Remarks
This method performs the following operations to synchronize the collection:
- Removes items from
originthat are not present innewItems. - Moves items within
originto match the order innewItems. - Inserts items from
newItemsintooriginif they are not already present.
origin matches the order and contents of newItems.
SynchronizeWith<T, U>(ObservableCollection<T>, IEnumerable<U>, Func<T, U, bool>?, Func<U, T>)
Synchronizes the contents of the ObservableCollection<T> with the specified collection of new items.
It essentially performs an incremental update to the origin collection based on the newItems.
public static void SynchronizeWith<T, U>(this ObservableCollection<T> origin, IEnumerable<U> newItems, Func<T, U, bool>? comparer, Func<U, T> convertToT)
Parameters
originObservableCollection<T>The ObservableCollection<T> to be synchronized.
newItemsIEnumerable<U>The collection of new items to synchronize with. If null, the
origincollection will be cleared.comparerFunc<T, U, bool>A function that compares items of type
Tfrom the original list with an item of typeUfrom the new list.convertToTFunc<U, T>A function that converts an item of type
Uto typeT.
Type Parameters
TThe type of elements in the ObservableCollection<T>.
UThe type of elements in the
newItemscollection.
Remarks
This method performs the following operations to synchronize the origin collection:
- Removes items from
originthat are not present innewItems. - Moves items within
originto match the order ofnewItems. - Inserts new items from
newItemsintooriginat the appropriate positions.
origin and newItems is based on the Equals(object) method.