to extension

This commit is contained in:
neuecc 2024-09-03 10:25:22 +09:00
parent 67c41178dd
commit bef0269e02
2 changed files with 30 additions and 28 deletions

View File

@ -50,4 +50,34 @@ namespace ObservableCollections
public interface INotifyCollectionChangedSynchronizedView<out TView> : IReadOnlyCollection<TView>, INotifyCollectionChanged, INotifyPropertyChanged, IDisposable public interface INotifyCollectionChangedSynchronizedView<out TView> : IReadOnlyCollection<TView>, INotifyCollectionChanged, INotifyPropertyChanged, IDisposable
{ {
} }
public static class ObservableCollectionExtensions
{
public static ISynchronizedViewList<T> ToViewList<T>(this IObservableCollection<T> collection)
{
return ToViewList(collection, static x => x);
}
public static ISynchronizedViewList<TView> ToViewList<T, TView>(this IObservableCollection<T> collection, Func<T, TView> transform)
{
// Optimized for non filtered
return new NonFilteredSynchronizedViewList<T, TView>(collection.CreateView(transform));
}
public static INotifyCollectionChangedSynchronizedView<T> ToNotifyCollectionChanged<T>(this IObservableCollection<T> collection)
{
return ToNotifyCollectionChanged(collection, null);
}
public static INotifyCollectionChangedSynchronizedView<T> ToNotifyCollectionChanged<T>(this IObservableCollection<T> collection, ICollectionEventDispatcher? collectionEventDispatcher)
{
return ToNotifyCollectionChanged(collection, static x => x, collectionEventDispatcher);
}
public static INotifyCollectionChangedSynchronizedView<TView> ToNotifyCollectionChanged<T, TView>(this IObservableCollection<T> collection, Func<T, TView> transform, ICollectionEventDispatcher? collectionEventDispatcher)
{
// Optimized for non filtered
return new NonFilteredNotifyCollectionChangedSynchronizedView<T, TView>(collection.CreateView(transform), collectionEventDispatcher);
}
}
} }

View File

@ -14,34 +14,6 @@ namespace ObservableCollections
return new View<TView>(this, transform); return new View<TView>(this, transform);
} }
public ISynchronizedViewList<T> ToViewList()
{
// NOTE: for more optimize, no need to create View.
return ToViewList(static x => x);
}
public ISynchronizedViewList<TView> ToViewList<TView>(Func<T, TView> transform)
{
// Optimized for non filtered
return new NonFilteredSynchronizedViewList<T, TView>(CreateView(transform));
}
public INotifyCollectionChangedSynchronizedView<T> ToNotifyCollectionChanged()
{
return ToNotifyCollectionChanged(null);
}
public INotifyCollectionChangedSynchronizedView<T> ToNotifyCollectionChanged(ICollectionEventDispatcher? collectionEventDispatcher)
{
return ToNotifyCollectionChanged(static x => x, collectionEventDispatcher);
}
public INotifyCollectionChangedSynchronizedView<TView> ToNotifyCollectionChanged<TView>(Func<T, TView> transform, ICollectionEventDispatcher? collectionEventDispatcher)
{
// Optimized for non filtered
return new NonFilteredNotifyCollectionChangedSynchronizedView<T, TView>(CreateView(transform), collectionEventDispatcher);
}
internal sealed class View<TView> : ISynchronizedView<T, TView> internal sealed class View<TView> : ISynchronizedView<T, TView>
{ {
public ISynchronizedViewFilter<T> Filter public ISynchronizedViewFilter<T> Filter