本文整理汇总了C#中ObservableDictionary.SuppressItemChangeNotifications方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableDictionary.SuppressItemChangeNotifications方法的具体用法?C# ObservableDictionary.SuppressItemChangeNotifications怎么用?C# ObservableDictionary.SuppressItemChangeNotifications使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableDictionary
的用法示例。
在下文中一共展示了ObservableDictionary.SuppressItemChangeNotifications方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsTrackingItemChangesReturnsCorrectValue
public void IsTrackingItemChangesReturnsCorrectValue()
{
// given
using (var observableDictionary = new ObservableDictionary<int, string>())
{
// when
using (observableDictionary.SuppressItemChangeNotifications())
{
observableDictionary.IsTrackingItemChanges.Should().BeFalse();
}
observableDictionary.IsTrackingItemChanges.Should().BeTrue();
}
}
示例2: SuppressItemChangedNotificationsSuppressesItemChangedNotifications
public void SuppressItemChangedNotificationsSuppressesItemChangedNotifications()
{
// given
var scheduler = new TestScheduler();
var observer = scheduler.CreateObserver<IObservableDictionaryChange<int, string>>();
var resetsObserver = scheduler.CreateObserver<Unit>();
var initialKvps = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One")
};
using (var observableDictionary = new ObservableDictionary<int, string>(initialKvps, scheduler: scheduler))
{
// when
observableDictionary.ThresholdAmountWhenChangesAreNotifiedAsReset = int.MaxValue;
IDisposable dictionaryItemChangesSubscription = null;
IDisposable resetsSubscription = null;
try
{
dictionaryItemChangesSubscription = observableDictionary.ValueChanges.Subscribe(observer);
resetsSubscription = observableDictionary.Resets.Subscribe(resetsObserver);
using (observableDictionary.SuppressItemChangeNotifications(false))
{
observableDictionary[1] = "Two";
scheduler.AdvanceBy(2);
}
scheduler.AdvanceBy(2);
// then
observer.Messages.Should().BeEmpty();
resetsObserver.Messages.Should().BeEmpty();
}
finally
{
dictionaryItemChangesSubscription?.Dispose();
resetsSubscription?.Dispose();
}
}
}
示例3: SuppressItemChangedNotificationsPreventsMultipleSuppressions
public void SuppressItemChangedNotificationsPreventsMultipleSuppressions()
{
// given
using (var observableDictionary = new ObservableDictionary<int, string>())
{
// when
using (observableDictionary.SuppressItemChangeNotifications())
{
Action action = () => { var secondSuppression = observableDictionary.SuppressItemChangeNotifications(); };
action
.ShouldThrow<InvalidOperationException>()
.WithMessage("An Item Change Notification Suppression is currently already ongoing, multiple concurrent suppressions are not supported.");
}
}
}
示例4: SuppressItemChangedNotificationsShouldThrowObjectDisposedExceptionAfterDictionaryDisposal
public void SuppressItemChangedNotificationsShouldThrowObjectDisposedExceptionAfterDictionaryDisposal()
{
// given
var observableDictionary = new ObservableDictionary<int, string>();
observableDictionary.Dispose();
// when
Action action = () => { var suppression = observableDictionary.SuppressItemChangeNotifications(); };
action
.ShouldThrow<ObjectDisposedException>()
.WithMessage($"Cannot access a disposed object.\r\nObject name: '{observableDictionary.GetType().Name}'.");
}
示例5: SuppressItemChangedNotificationsNotifiesResetWhenSuppressionIsDisposedIfRequested
public void SuppressItemChangedNotificationsNotifiesResetWhenSuppressionIsDisposedIfRequested()
{
// given
var scheduler = new TestScheduler();
var dictionaryChangesObserver = scheduler.CreateObserver<IObservableDictionaryChange<int, string>>();
var dictionaryItemChangesObserver = scheduler.CreateObserver<IObservableDictionaryChange<int, string>>();
var resetsObserver = scheduler.CreateObserver<Unit>();
var initialKvps = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One")
};
using (var observableDictionary = new ObservableDictionary<int, string>(initialKvps, scheduler: scheduler))
{
// when
observableDictionary.ThresholdAmountWhenChangesAreNotifiedAsReset = int.MaxValue;
IDisposable dictionaryChangesSubscription = null;
IDisposable dictionaryItemChangesSubscription = null;
IDisposable resetsSubscription = null;
try
{
dictionaryChangesSubscription = observableDictionary.DictionaryChanges.Subscribe(dictionaryChangesObserver);
dictionaryItemChangesSubscription = observableDictionary.ValueChanges.Subscribe(dictionaryItemChangesObserver);
resetsSubscription = observableDictionary.Resets.Subscribe(resetsObserver);
using (observableDictionary.SuppressItemChangeNotifications(true))
{
observableDictionary[1] = "Two";
scheduler.AdvanceBy(4);
}
scheduler.AdvanceBy(4);
// then
resetsObserver.Messages.Count.Should().Be(1);
dictionaryItemChangesObserver.Messages.Count.Should().Be(0);
dictionaryChangesObserver.Messages.Count.Should().Be(1);
dictionaryChangesObserver.Messages.First().Value.Value.ChangeType.Should().Be(ObservableDictionaryChangeType.Reset);
dictionaryChangesObserver.Messages.First().Value.Value.Key.Should().Be(default(int));
dictionaryChangesObserver.Messages.First().Value.Value.Value.Should().Be(default(string));
dictionaryChangesObserver.Messages.First().Value.Value.OldValue.Should().Be(default(string));
dictionaryChangesObserver.Messages.First().Value.Value.ChangedPropertyName.Should().BeEmpty();
}
finally
{
dictionaryChangesSubscription?.Dispose();
dictionaryItemChangesSubscription?.Dispose();
resetsSubscription?.Dispose();
}
}
}