本文整理汇总了C#中ObservableDictionary.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableDictionary.Dispose方法的具体用法?C# ObservableDictionary.Dispose怎么用?C# ObservableDictionary.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableDictionary
的用法示例。
在下文中一共展示了ObservableDictionary.Dispose方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddOfCollectionOfKeyValuePairsShouldThrowDisposedExceptionAfterDisposal
public void AddOfCollectionOfKeyValuePairsShouldThrowDisposedExceptionAfterDisposal()
{
// given
var observableDictionary = new ObservableDictionary<int, string>();
observableDictionary.Dispose();
// when
Action action = () => { ((ICollection<KeyValuePair<int, string>>) observableDictionary).Add(new KeyValuePair<int, string>(1, "One")); };
// then
action.ShouldThrow<ObjectDisposedException>();
}
示例2: SuppressResetNotificationsShouldThrowObjectDisposedExceptionAfterDictionaryDisposal
public void SuppressResetNotificationsShouldThrowObjectDisposedExceptionAfterDictionaryDisposal()
{
// given
var observableDictionary = new ObservableDictionary<int, string>();
observableDictionary.Dispose();
// when
Action action = () => { var suppression = observableDictionary.SuppressResetNotifications(); };
action
.ShouldThrow<ObjectDisposedException>()
.WithMessage($"Cannot access a disposed object.\r\nObject name: '{observableDictionary.GetType().Name}'.");
}
示例3: ShouldThrowDisposedExceptionWhenTryGetOfReadOnlyDictionaryOfKeyValuePairsIsCalledAfterDisposal
public void ShouldThrowDisposedExceptionWhenTryGetOfReadOnlyDictionaryOfKeyValuePairsIsCalledAfterDisposal()
{
// given
var observableDictionary = new ObservableDictionary<string, string>();
observableDictionary.Dispose();
// when
string value;
Action action = () => ((IReadOnlyDictionary<string, string>) observableDictionary).TryGetValue("One", out value);
// then
action.ShouldThrow<ObjectDisposedException>();
}
示例4: ShouldThrowDisposedExceptionWhenAccessingReadOnlyDictionaryOfKeyValuePairsPropertiesAfterDisposal
public void ShouldThrowDisposedExceptionWhenAccessingReadOnlyDictionaryOfKeyValuePairsPropertiesAfterDisposal()
{
// given
var observableDictionary = new ObservableDictionary<int, string>();
observableDictionary.Dispose();
// when
Action keysPropertyAccessAction = () => { var keys = ((IReadOnlyDictionary<int, string>) observableDictionary).Keys; };
Action valuesPropertyAccessAction = () => { var values = ((IReadOnlyDictionary<int, string>) observableDictionary).Values; };
// then
keysPropertyAccessAction.ShouldThrow<ObjectDisposedException>();
valuesPropertyAccessAction.ShouldThrow<ObjectDisposedException>();
}
示例5: ShouldThrowDisposedExceptionWhenReadOnlyDictionaryOfKeyValuePairsContainsKeyIsCalledAfterDisposal
public void ShouldThrowDisposedExceptionWhenReadOnlyDictionaryOfKeyValuePairsContainsKeyIsCalledAfterDisposal()
{
// given
var observableDictionary = new ObservableDictionary<int, string>();
observableDictionary.Dispose();
// when
Action action = () => { var value = ((IReadOnlyDictionary<int, string>) observableDictionary).ContainsKey(1); };
// then
action.ShouldThrow<ObjectDisposedException>();
}
示例6: ShouldThrowDisposedExceptionWhenAccessingCollectionPropertiesAfterDisposal
public void ShouldThrowDisposedExceptionWhenAccessingCollectionPropertiesAfterDisposal()
{
// given
var observableDictionary = new ObservableDictionary<int, string>();
observableDictionary.Dispose();
// when
Action syncRootPropertyAccess = () => { var syncRoot = ((ICollection) observableDictionary).SyncRoot; };
Action countPropertyAccess = () => { var count = ((ICollection) observableDictionary).Count; };
Action isSynchronizedPropertyAccess = () => { var isSynchronized = ((ICollection) observableDictionary).IsSynchronized; };
// then
syncRootPropertyAccess.ShouldThrow<ObjectDisposedException>();
countPropertyAccess.ShouldThrow<ObjectDisposedException>();
isSynchronizedPropertyAccess.ShouldThrow<ObjectDisposedException>();
}
示例7: ShouldThrowDisposedExceptionWhenAccessingCollectionOfKeyValuePairsPropertiesAfterDisposal
public void ShouldThrowDisposedExceptionWhenAccessingCollectionOfKeyValuePairsPropertiesAfterDisposal()
{
// given
var observableDictionary = new ObservableDictionary<int, string>();
observableDictionary.Dispose();
// when
Action isReadOnlyPropertyAccessAction = () => { var isReadOnly = ((ICollection<KeyValuePair<int, string>>) observableDictionary).IsReadOnly; };
Action countPropertyAccessAction = () => { var count = ((ICollection<KeyValuePair<int, string>>) observableDictionary).Count; };
// then
isReadOnlyPropertyAccessAction.ShouldThrow<ObjectDisposedException>();
countPropertyAccessAction.ShouldThrow<ObjectDisposedException>();
}
示例8: RemoveOfCollectionOfKeyValuePairsShouldThrowDisposedExceptionAfterDisposal
public void RemoveOfCollectionOfKeyValuePairsShouldThrowDisposedExceptionAfterDisposal()
{
// given
var initialKvPs = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One")
};
var observableDictionary = new ObservableDictionary<int, string>(initialKvPs);
observableDictionary.Dispose();
// when
Action action = () => { ((ICollection<KeyValuePair<int, string>>) observableDictionary).Remove(new KeyValuePair<int, string>(1, "One")); };
// then
action.ShouldThrow<ObjectDisposedException>();
}
示例9: GetEnumeratorOfEnumerableShouldThrowDisposedExceptionAfterDisposal
public void GetEnumeratorOfEnumerableShouldThrowDisposedExceptionAfterDisposal()
{
// given
var observableDictionary = new ObservableDictionary<int, string>();
observableDictionary.Dispose();
// when
Action action = () => { var enumerator = ((IEnumerable) observableDictionary).GetEnumerator(); };
// then
action.ShouldThrow<ObjectDisposedException>();
}
示例10: CopyToOfCollectionShouldThrowDisposedExceptionAfterDisposal
public void CopyToOfCollectionShouldThrowDisposedExceptionAfterDisposal()
{
// given
var initialKvPs = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One"),
new KeyValuePair<int, string>(2, "Two")
};
var observableDictionary = new ObservableDictionary<int, string>(initialKvPs);
observableDictionary.Dispose();
// when
Action action = () =>
{
var targetArray = new KeyValuePair<int, string>[observableDictionary.Count];
((ICollection) observableDictionary).CopyTo(targetArray, 0);
};
// then
action.ShouldThrow<ObjectDisposedException>();
}