本文整理汇总了C#中ObservableDictionary.TryRemoveRange方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableDictionary.TryRemoveRange方法的具体用法?C# ObservableDictionary.TryRemoveRange怎么用?C# ObservableDictionary.TryRemoveRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableDictionary
的用法示例。
在下文中一共展示了ObservableDictionary.TryRemoveRange方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryRemoveRangeOfKeyValuePairsThrowsOnNullKeyValuePairs
public void TryRemoveRangeOfKeyValuePairsThrowsOnNullKeyValuePairs()
{
// given
using (var observableDictionary = new ObservableDictionary<int, string>())
{
// when
IDictionary<int, string> nonRemovables;
bool removalResult = false;
Action action = () => observableDictionary.TryRemoveRange(null, out nonRemovables);
// then check whether all items have been accounted for
action
.ShouldThrow<ArgumentNullException>()
.WithMessage("Value cannot be null.\r\nParameter name: items");
}
}
示例2: TryRemoveRangeOfKeyValuePairsRemovesExistingItemsAndReportsNonremovablesBack
public void TryRemoveRangeOfKeyValuePairsRemovesExistingItemsAndReportsNonremovablesBack()
{
// given
var keyValuePairs = Enumerable.Range(0, 100)
.Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
.ToList();
var keyValuePairsToRemove = Enumerable.Range(50, 100)
.Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
.ToList();
using (var observableDictionary = new ObservableDictionary<int, string>(keyValuePairs))
{
// when
IDictionary<int, string> nonRemovedKeyValuePairs;
var tryRemoveResult = observableDictionary.TryRemoveRange(keyValuePairsToRemove, out nonRemovedKeyValuePairs);
// then check whether all items have been accounted for
tryRemoveResult.Should().Be(false);
nonRemovedKeyValuePairs.Should().NotBeNull();
nonRemovedKeyValuePairs.Should().NotBeEmpty();
nonRemovedKeyValuePairs.Count.Should().Be(50);
observableDictionary.Count.Should().Be(50);
// check whether everything that was reported as removable is removed
foreach (var keyValuePair in keyValuePairsToRemove.Except(nonRemovedKeyValuePairs))
{
observableDictionary.Should().NotContain(keyValuePair);
}
foreach (var keyValuePair in nonRemovedKeyValuePairs)
{
observableDictionary.Should().NotContain(keyValuePair);
}
// and check whether all other one(s) are still there, too
foreach (var keyValuePair in keyValuePairs.Except(keyValuePairsToRemove))
{
observableDictionary.Should().Contain(keyValuePair);
}
}
}
示例3: TryRemoveRangeOfKeyValuePairsForCornerCasesRemovesExistingItemsAndReportsNonremovablesBack
public void TryRemoveRangeOfKeyValuePairsForCornerCasesRemovesExistingItemsAndReportsNonremovablesBack(int initialAmountOfItems, int amountOfItemsToRemove)
{
// given
var keyValuePairs = Enumerable.Range(0, initialAmountOfItems)
.Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
.ToList();
var keyValuePairsToRemove = Enumerable.Range(0, amountOfItemsToRemove)
.Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
.ToList();
using (var observableDictionary = new ObservableDictionary<int, string>(keyValuePairs))
{
// when
IDictionary<int, string> nonRemovedKeyValuePairs;
var tryRemoveResult = observableDictionary.TryRemoveRange(keyValuePairsToRemove, out nonRemovedKeyValuePairs);
// then check whether all items have been accounted for
tryRemoveResult.Should().Be(false);
nonRemovedKeyValuePairs.Should().NotBeNull();
nonRemovedKeyValuePairs.Should().NotBeEmpty();
observableDictionary.Count.Should().Be(initialAmountOfItems - amountOfItemsToRemove + nonRemovedKeyValuePairs.Count);
// check whether everything that was reported as removable is removed
foreach (var keyValuePair in keyValuePairsToRemove.Except(nonRemovedKeyValuePairs))
{
observableDictionary.Should().NotContain(keyValuePair);
}
foreach (var keyValuePair in nonRemovedKeyValuePairs)
{
observableDictionary.Should().NotContain(keyValuePair);
}
}
}
示例4: TryRemoveRangeOfKeyValuePairsRemovesExistingItems
public void TryRemoveRangeOfKeyValuePairsRemovesExistingItems(int initialAmountOfItems)
{
// given
var keyValuePairs = Enumerable.Range(0, initialAmountOfItems)
.Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
.ToList();
using (var observableDictionary = new ObservableDictionary<int, string>(keyValuePairs))
{
// when
IDictionary<int, string> nonRemovables;
var removalResult = observableDictionary.TryRemoveRange(keyValuePairs, out nonRemovables);
// then check whether all items have been accounted for
removalResult.Should().Be(true);
observableDictionary.Count.Should().Be(0);
nonRemovables.Should().NotBeNull();
nonRemovables.Should().BeEmpty();
}
}
示例5: TryRemoveRangeOfKeysRemovesExistingItems
public void TryRemoveRangeOfKeysRemovesExistingItems(int initialAmountOfItems)
{
// given
var keyValuePairs = Enumerable.Range(0, initialAmountOfItems)
.Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
.ToList();
var keysForKeyValuePairs = keyValuePairs.Select(kvp => kvp.Key);
using (var observableDictionary = new ObservableDictionary<int, string>(keyValuePairs))
{
// when
IList<int> nonRemovables = new List<int>();
Action action = () => observableDictionary.TryRemoveRange(keysForKeyValuePairs, out nonRemovables);
// then check whether all items have been accounted for
action.ShouldNotThrow();
observableDictionary.Count.Should().Be(0);
nonRemovables.Should().NotBeNull();
nonRemovables.Should().BeEmpty();
}
}