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


C# ObservableDictionary.TryRemoveRange方法代码示例

本文整理汇总了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");
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:16,代码来源:ObservableDictionaryModificationTests.cs

示例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);
                }
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:44,代码来源:ObservableDictionaryModificationTests.cs

示例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);
                }
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:37,代码来源:ObservableDictionaryModificationTests.cs

示例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();
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:22,代码来源:ObservableDictionaryModificationTests.cs

示例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();
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:23,代码来源:ObservableDictionaryModificationTests.cs


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