Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/ObservableCollections/IObservableCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public interface INotifyCollectionChangedSynchronizedViewList<TView> : IList<TVi
{
}

// IColleciton<T>.Count and ICollection.Count will be ambigious so use abstract class instead of interface
// ICollection<T>.Count and ICollection.Count will be ambiguous so use abstract class instead of interface
public abstract class NotifyCollectionChangedSynchronizedViewList<TView> :
INotifyCollectionChangedSynchronizedViewList<TView>,
IWritableSynchronizedViewList<TView>,
Expand Down Expand Up @@ -232,5 +232,11 @@ public static NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollect
// Optimized for non filtered
return new NonFilteredSynchronizedViewList<T, TView>(collection.CreateView(transform), isSupportRangeFeature: false, collectionEventDispatcher, null);
}

public static NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollectionChanged<T, TView>(this IObservableCollection<T> collection, Func<T, TView> transform, bool supportsRangeFeature, ICollectionEventDispatcher? collectionEventDispatcher)
{
// Optimized for non filtered
return new NonFilteredSynchronizedViewList<T, TView>(collection.CreateView(transform), supportsRangeFeature, collectionEventDispatcher, null);
}
}
}
7 changes: 6 additions & 1 deletion src/ObservableCollections/ObservableDictionary.Views.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollectionChan
return new FiltableSynchronizedViewList<KeyValuePair<TKey, TValue>, TView>(this, isSupportRangeFeature: false, collectionEventDispatcher);
}

public NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollectionChanged(bool supportsRangeFeature, ICollectionEventDispatcher? collectionEventDispatcher)
{
return new FiltableSynchronizedViewList<KeyValuePair<TKey, TValue>, TView>(this, supportsRangeFeature, collectionEventDispatcher);
}

public IEnumerator<TView> GetEnumerator()
{
lock (SyncRoot)
Expand Down Expand Up @@ -221,4 +226,4 @@ private void SourceCollectionChanged(in NotifyCollectionChangedEventArgs<KeyValu
}
}
}
}
}
5 changes: 5 additions & 0 deletions src/ObservableCollections/ObservableHashSet.Views.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollectionChan
return new FiltableSynchronizedViewList<T, TView>(this, isSupportRangeFeature: false, collectionEventDispatcher);
}

public NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollectionChanged(bool supportsRangeFeature, ICollectionEventDispatcher? collectionEventDispatcher)
{
return new FiltableSynchronizedViewList<T, TView>(this, supportsRangeFeature, collectionEventDispatcher);
}

public IEnumerator<TView> GetEnumerator()
{
lock (SyncRoot)
Expand Down
27 changes: 27 additions & 0 deletions src/ObservableCollections/ObservableList.Views.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public NotifyCollectionChangedSynchronizedViewList<TView> ToWritableNotifyCollec
return new NonFilteredSynchronizedViewList<T, TView>(CreateView(transform), isSupportRangeFeature: false, collectionEventDispatcher, converter);
}

public NotifyCollectionChangedSynchronizedViewList<TView> ToWritableNotifyCollectionChanged<TView>(Func<T, TView> transform, bool supportsRangeFeature, WritableViewChangedEventHandler<T, TView>? converter, ICollectionEventDispatcher? collectionEventDispatcher)
{
return new NonFilteredSynchronizedViewList<T, TView>(CreateView(transform), supportsRangeFeature, collectionEventDispatcher, converter);
}

internal sealed class View<TView> : ISynchronizedView<T, TView>, IWritableSynchronizedView<T, TView>
{
public ISynchronizedViewFilter<T, TView> Filter
Expand Down Expand Up @@ -154,6 +159,11 @@ public NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollectionChan
return new FiltableSynchronizedViewList<T, TView>(this, isSupportRangeFeature: false, collectionEventDispatcher);
}

public NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollectionChanged(bool supportsRangeFeature, ICollectionEventDispatcher? collectionEventDispatcher)
{
return new FiltableSynchronizedViewList<T, TView>(this, supportsRangeFeature, collectionEventDispatcher);
}

public IEnumerator<TView> GetEnumerator()
{
lock (SyncRoot)
Expand Down Expand Up @@ -432,11 +442,28 @@ public NotifyCollectionChangedSynchronizedViewList<TView> ToWritableNotifyCollec
});
}

public NotifyCollectionChangedSynchronizedViewList<TView> ToWritableNotifyCollectionChanged(bool supportsRangeFeature, ICollectionEventDispatcher? collectionEventDispatcher)
{
return new FiltableSynchronizedViewList<T, TView>(this,
supportsRangeFeature,
eventDispatcher: collectionEventDispatcher,
converter: static (TView newView, T originalValue, ref bool setValue) =>
{
setValue = true;
return originalValue;
});
}

public NotifyCollectionChangedSynchronizedViewList<TView> ToWritableNotifyCollectionChanged(WritableViewChangedEventHandler<T, TView> converter, ICollectionEventDispatcher? collectionEventDispatcher)
{
return new FiltableSynchronizedViewList<T, TView>(this, isSupportRangeFeature: false, collectionEventDispatcher, converter);
}

public NotifyCollectionChangedSynchronizedViewList<TView> ToWritableNotifyCollectionChanged(bool supportsRangeFeature, WritableViewChangedEventHandler<T, TView> converter, ICollectionEventDispatcher? collectionEventDispatcher)
{
return new FiltableSynchronizedViewList<T, TView>(this, supportsRangeFeature, collectionEventDispatcher, converter);
}

#endregion

sealed class IgnoreViewComparer : IComparer<(T, TView)>
Expand Down
7 changes: 6 additions & 1 deletion src/ObservableCollections/ObservableQueue.Views.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollectionChan
return new FiltableSynchronizedViewList<T, TView>(this, isSupportRangeFeature: false, collectionEventDispatcher);
}

public NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollectionChanged(bool supportsRangeFeature, ICollectionEventDispatcher? collectionEventDispatcher)
{
return new FiltableSynchronizedViewList<T, TView>(this, supportsRangeFeature, collectionEventDispatcher);
}

public IEnumerator<TView> GetEnumerator()
{
lock (SyncRoot)
Expand Down Expand Up @@ -228,4 +233,4 @@ private void SourceCollectionChanged(in NotifyCollectionChangedEventArgs<T> e)
}
}
}
}
}
10 changes: 9 additions & 1 deletion src/ObservableCollections/ObservableRingBuffer.Views.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ public NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollectionChan
}
}

public NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollectionChanged(bool supportsRangeFeature, ICollectionEventDispatcher? collectionEventDispatcher)
{
lock (SyncRoot)
{
return new FiltableSynchronizedViewList<T, TView>(this, supportsRangeFeature, collectionEventDispatcher);
}
}

public IEnumerator<TView> GetEnumerator()
{
lock (SyncRoot)
Expand Down Expand Up @@ -291,4 +299,4 @@ private void SourceCollectionChanged(in NotifyCollectionChangedEventArgs<T> e)
}
}
}
}
}
8 changes: 8 additions & 0 deletions src/ObservableCollections/ObservableStack.Views.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ public NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollectionChan
}
}

public NotifyCollectionChangedSynchronizedViewList<TView> ToNotifyCollectionChanged(bool supportsRangeFeature, ICollectionEventDispatcher? collectionEventDispatcher)
{
lock (SyncRoot)
{
return new FiltableSynchronizedViewList<T, TView>(this, supportsRangeFeature, collectionEventDispatcher);
}
}

public IEnumerator<TView> GetEnumerator()
{
lock (SyncRoot)
Expand Down
4 changes: 2 additions & 2 deletions src/ObservableCollections/SynchronizedViewList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal sealed class FiltableSynchronizedViewList<T, TView> : NotifyCollectionC

readonly ISynchronizedView<T, TView> parent;
readonly AlternateIndexList<TView> listView;
readonly bool isSupportRangeFeature; // WPF, Avalonia etc does not support range notification
readonly bool isSupportRangeFeature; // WPF, etc does not support range notification

readonly ICollectionEventDispatcher eventDispatcher;
readonly WritableViewChangedEventHandler<T, TView>? converter; // null = readonly
Expand Down Expand Up @@ -522,7 +522,7 @@ internal sealed class NonFilteredSynchronizedViewList<T, TView> : NotifyCollecti

readonly ISynchronizedView<T, TView> parent;
readonly List<TView> listView; // no filter can be faster
readonly bool isSupportRangeFeature; // WPF, Avalonia etc does not support range notification
readonly bool isSupportRangeFeature; // WPF, etc does not support range notification

readonly ICollectionEventDispatcher eventDispatcher;
readonly WritableViewChangedEventHandler<T, TView>? converter; // null = readonly
Expand Down