Skip to content

Commit c60e34e

Browse files
Merge pull request #40 from ShawnLaMountain/Net10-Upgrade
Updated Observable Collections to have a Reset to notify UI to update
2 parents 4f9cdc5 + a481cf0 commit c60e34e

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎src/ThunderDesign.Net-PCL.Threading/Collections/ObservableCollectionThreadSafe.cs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@ public void Move(int oldIndex, int newIndex)
9696
}
9797
}
9898

99+
public void Reset()
100+
{
101+
var notifyAndWait = WaitOnNotifying;
102+
103+
if (notifyAndWait)
104+
_ReaderWriterLockSlim.EnterUpgradeableReadLock();
105+
try
106+
{
107+
OnPropertyChanged(nameof(Count));
108+
OnPropertyChanged(_IndexerName);
109+
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
110+
}
111+
finally
112+
{
113+
if (notifyAndWait)
114+
_ReaderWriterLockSlim.ExitUpgradeableReadLock();
115+
}
116+
}
117+
99118
public new void Add(T item)
100119
{
101120
var notifyAndWait = WaitOnNotifying;

‎src/ThunderDesign.Net-PCL.Threading/Collections/ObservableDictionaryThreadSafe.cs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,26 @@ public bool WaitOnNotifying
169169
return result;
170170
}
171171

172+
public void Reset()
173+
{
174+
var notifyAndWait = WaitOnNotifying;
175+
176+
if (notifyAndWait)
177+
_ReaderWriterLockSlim.EnterUpgradeableReadLock();
178+
try
179+
{
180+
OnPropertyChanged(nameof(Keys));
181+
OnPropertyChanged(nameof(Values));
182+
OnPropertyChanged(nameof(Count));
183+
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
184+
}
185+
finally
186+
{
187+
if (notifyAndWait)
188+
_ReaderWriterLockSlim.ExitUpgradeableReadLock();
189+
}
190+
}
191+
172192
#if NET6_0_OR_GREATER
173193
public new bool TryAdd(TKey key, TValue value)
174194
{

‎src/ThunderDesign.Net-PCL.Threading/Interfaces/IObservableCollectionThreadSafe.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public interface IObservableCollectionThreadSafe : ICollectionThreadSafe, IBinda
99
{
1010
#region methods
1111
void Move(int oldIndex, int newIndex);
12+
void Reset();
1213
#endregion
1314
}
1415

‎src/ThunderDesign.Net-PCL.Threading/Interfaces/IObservableDictionaryThreadSafe.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace ThunderDesign.Net.Threading.Interfaces
55
{
66
public interface IObservableDictionaryThreadSafe : IDictionaryThreadSafe, IBindableCollection
77
{
8+
void Reset();
89
}
910

1011
public interface IObservableDictionaryThreadSafe<TKey, TValue> : IDictionaryThreadSafe<TKey, TValue>, IObservableDictionaryThreadSafe

0 commit comments

Comments
 (0)