当前位置: 首页>>代码示例>>C#>>正文


C# ObservableDictionary.RemoveRange方法代码示例

本文整理汇总了C#中ObservableDictionary.RemoveRange方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableDictionary.RemoveRange方法的具体用法?C# ObservableDictionary.RemoveRange怎么用?C# ObservableDictionary.RemoveRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObservableDictionary的用法示例。


在下文中一共展示了ObservableDictionary.RemoveRange方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoveRangeRaisesPropertyChangedEventForItemIndexerAndCount

        public void RemoveRangeRaisesPropertyChangedEventForItemIndexerAndCount()
        {
            // given
            var items = new List<KeyValuePair<int, string>>()
                {
                    new KeyValuePair<int, string>(1, "One"),
                    new KeyValuePair<int, string>(2, "Two"),
                    new KeyValuePair<int, string>(3, "Three"),
                };

            using (var observableDictionary = new ObservableDictionary<int, string>(items))
            {
                observableDictionary.ThresholdAmountWhenChangesAreNotifiedAsReset = 0;
                observableDictionary.MonitorEvents();

                // when
                observableDictionary.RemoveRange(items);

                // then
                observableDictionary
                    .ShouldRaise(nameof(observableDictionary.PropertyChanged))
                    .WithSender(observableDictionary)
                    .WithArgs<PropertyChangedEventArgs>(args => args.PropertyName == "Item[]");

                observableDictionary
                    .ShouldRaise(nameof(observableDictionary.PropertyChanged))
                    .WithSender(observableDictionary)
                    .WithArgs<PropertyChangedEventArgs>(args => args.PropertyName == nameof(observableDictionary.Count));
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:30,代码来源:ObservableDictionaryNotificationTests.cs

示例2: using

        public void RemoveRangeRaisesPropertyChangedEventForItemIndexerAndCountOnlyOnceWhenThresholdAmountWhenItemChangesAreNotifiedAsResetIsSetAccordingly()
        {
            // given
            var items = new List<KeyValuePair<int, string>>()
                {
                    new KeyValuePair<int, string>(1, "One"),
                    new KeyValuePair<int, string>(2, "Two"),
                    new KeyValuePair<int, string>(3, "Three"),
                };

            using (var observableDictionary = new ObservableDictionary<int, string>(items))
            {
                observableDictionary.ThresholdAmountWhenChangesAreNotifiedAsReset = 0;
                observableDictionary.MonitorEvents();

                // when
                observableDictionary.RemoveRange(items);

                // then
                observableDictionary
                    .ShouldRaise(nameof(observableDictionary.PropertyChanged))
                    .WithSender(observableDictionary)
                    .WithArgs<PropertyChangedEventArgs>(args => args.PropertyName == "Item[]")
                    .Should().HaveCount(1); // ToDo: re-enable test if/when https://github.com/dennisdoomen/fluentassertions/issues/337 has been fixed

                observableDictionary
                    .ShouldRaise(nameof(observableDictionary.PropertyChanged))
                    .WithSender(observableDictionary)
                    .WithArgs<PropertyChangedEventArgs>(args => args.PropertyName == nameof(observableDictionary.Count))
                    .Should().HaveCount(1); // ToDo: re-enable test if/when https://github.com/dennisdoomen/fluentassertions/issues/337 has been fixed
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:32,代码来源:ObservableDictionaryNotificationTests.cs

示例3: RemoveRangeOfKeyValuePairsThrowsOnNonExistingItems

        public void RemoveRangeOfKeyValuePairsThrowsOnNonExistingItems()
        {
            // given
            using (var observableDictionary = new ObservableDictionary<int, string>())
            {
                // when
                Action invalidRemoveRangeForNonExistingKey = () => observableDictionary.RemoveRange(new List<KeyValuePair<int, string>>() {new KeyValuePair<int, string>(10, "Ten")});

                // then
                invalidRemoveRangeForNonExistingKey
                    .ShouldThrow<ArgumentOutOfRangeException>()
                    .WithMessage("The following key/value pair(s) are not in this dictionary and cannot be removed from it: [10, Ten]\r\nParameter name: items");

                observableDictionary.Count.Should().Be(0);
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:16,代码来源:ObservableDictionaryModificationTests.cs

示例4: RemoveRangeOfKeyValuePairsThrowsOnNullItems

        public void RemoveRangeOfKeyValuePairsThrowsOnNullItems()
        {
            // given
            using (var observableDictionary = new ObservableDictionary<int, string>())
            {
                // when
                Action action = () => observableDictionary.RemoveRange((List<KeyValuePair<int, string>>) null);

                // then
                action
                    .ShouldThrow<ArgumentNullException>()
                    .WithMessage("Value cannot be null.\r\nParameter name: items");

                observableDictionary.Count.Should().Be(0);
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:16,代码来源:ObservableDictionaryModificationTests.cs

示例5: RemoveRangeOfKeyValuePairsRemovesItems

        public void RemoveRangeOfKeyValuePairsRemovesItems(int initialAmountOfItems, int amountsOfItemsToRemove)
        {
            // given
            var keyValuePairs = Enumerable.Range(0, initialAmountOfItems)
                .Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
                .ToList();

            var keyValuePairsToRemove = Enumerable.Range(0, amountsOfItemsToRemove)
                .Select(i => new KeyValuePair<int, string>(i, $"#{i}"))
                .ToDictionary(keyValuePair => keyValuePair.Key, keyValuePair => keyValuePair.Value).ToList();

            using (var observableDictionary = new ObservableDictionary<int, string>(keyValuePairs))
            {
                // when
                observableDictionary.RemoveRange(keyValuePairsToRemove);

                // then check whether all items have been accounted for
                observableDictionary.Count.Should().Be(initialAmountOfItems - amountsOfItemsToRemove);

                foreach (var removedKeyValuePair in keyValuePairsToRemove)
                {
                    observableDictionary.Should().NotContain(removedKeyValuePair);
                }
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:25,代码来源:ObservableDictionaryModificationTests.cs


注:本文中的ObservableDictionary.RemoveRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。