| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="ObservableRangeCollectionExtensions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.ComponentModel; |
| | | 9 | | |
| | | 10 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 11 | | namespace MyNet.Collections; |
| | | 12 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 13 | | |
| | | 14 | | public static class ObservableRangeCollectionExtensions |
| | | 15 | | { |
| | | 16 | | extension<T>(ObservableRangeCollection<T> collection) |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Sorts the collection using an external sorting strategy. |
| | | 20 | | /// </summary> |
| | | 21 | | public void SortBy(Func<T, object> selector, ListSortDirection direction = ListSortDirection.Ascending, ICollect |
| | | 22 | | { |
| | 15 | 23 | | ArgumentNullException.ThrowIfNull(collection); |
| | 15 | 24 | | ArgumentNullException.ThrowIfNull(selector); |
| | | 25 | | |
| | 15 | 26 | | var sorted = (sorter ?? DefaultCollectionSorter<T>.Default).Sort(collection, selector, direction); |
| | 15 | 27 | | collection.Load(sorted); |
| | 15 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Wraps the collection in a synchronized adapter. |
| | | 32 | | /// </summary> |
| | | 33 | | public SynchronizedObservableCollection<T> Synchronized(ICollectionSynchronizer? synchronizer = null) |
| | | 34 | | { |
| | 3 | 35 | | ArgumentNullException.ThrowIfNull(collection); |
| | 3 | 36 | | return new(collection, synchronizer); |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Wraps an observable range collection so notifications are dispatched with the specified dispatcher. |
| | | 41 | | /// </summary> |
| | | 42 | | public DispatchedObservableCollection<T> Dispatched(ICollectionEventDispatcher dispatcher) |
| | | 43 | | { |
| | 3 | 44 | | ArgumentNullException.ThrowIfNull(collection); |
| | 3 | 45 | | ArgumentNullException.ThrowIfNull(dispatcher); |
| | 3 | 46 | | return new(collection, dispatcher); |
| | | 47 | | } |
| | | 48 | | } |
| | | 49 | | } |
| | | 50 | | |