本文整理汇总了C#中ObservableDictionary.TryUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableDictionary.TryUpdate方法的具体用法?C# ObservableDictionary.TryUpdate怎么用?C# ObservableDictionary.TryUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableDictionary
的用法示例。
在下文中一共展示了ObservableDictionary.TryUpdate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryUpdateThrowsOnNullKey
public void TryUpdateThrowsOnNullKey()
{
// given
using (var observableDictionary = new ObservableDictionary<string, string>())
{
// when
Action action = () => observableDictionary.TryUpdate((string) null, "Null");
// then
action
.ShouldThrow<ArgumentNullException>()
.WithMessage("Value cannot be null.\r\nParameter name: key");
observableDictionary.Count.Should().Be(0);
}
}
示例2: TryUpdateUpdatesExistingItem
public void TryUpdateUpdatesExistingItem()
{
// given
var initialKvPs = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One")
};
using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
{
// when
var updateResult = observableDictionary.TryUpdate(1, "Two");
// then
updateResult.Should().Be(true);
observableDictionary.Count.Should().Be(1);
observableDictionary.Should().Contain(1, "Two");
observableDictionary.Keys.Should().Contain(1);
observableDictionary.Values.Should().NotContain("One");
observableDictionary.Values.Should().Contain("Two");
}
}
示例3: TryUpdateDoesNotUpdateNonExistingItem
public void TryUpdateDoesNotUpdateNonExistingItem()
{
// given
var initialKvPs = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(1, "One")
};
using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
{
// when
var updateResult = observableDictionary.TryUpdate(2, "One");
// then
updateResult.Should().Be(false);
observableDictionary.Count.Should().Be(1);
observableDictionary.Should().Contain(1, "One");
}
}