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


C# AttributeCollection.Remove方法代码示例

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


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

示例1: TestRemovingInvalidAttribute

        public void TestRemovingInvalidAttribute()
        {
            AttributeCollection attributes = new AttributeCollection();

            attributes.Add("Test1", new AttributeValue("Test Value1"));
            attributes.Add("Test2", new AttributeValue("Test Value2"));
            attributes.Add("Test3", new AttributeValue("Test Value3"));
            attributes.Add("Test4", new AttributeValue("Test Value4"));

            Assert.IsFalse(attributes.Remove("Test5"));
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:11,代码来源:AttributeCollectionTests.cs

示例2: TestCollectionChangedWithRemove

        public void TestCollectionChangedWithRemove()
        {
            AttributeCollection attributes = new AttributeCollection();

            bool eventRaised = false;
            NotifyCollectionChangedAction action = NotifyCollectionChangedAction.Reset;
            int newIndex = -1;
            string newAttributeName = string.Empty;
            AttributeValue newAttributeValue = null;
            int oldIndex = -1;
            string oldAttributeName = string.Empty;
            AttributeValue oldAttributeValue = null;

            attributes.Add("Test1", new AttributeValue("Test Value1"));

            // Setup the event handler
            attributes.CollectionChanged += (object sender, NotifyCollectionChangedEventArgs e) =>
            {
                action = e.Action;
                newAttributeName = e.NewItems != null ? ((KeyValuePair<string, AttributeValue>)e.NewItems[0]).Key : string.Empty;
                newAttributeValue = e.NewItems != null ? ((KeyValuePair<string, AttributeValue>)e.NewItems[0]).Value : null;
                newIndex = e.NewStartingIndex;
                oldAttributeName = e.OldItems != null ? ((KeyValuePair<string, AttributeValue>)e.OldItems[0]).Key : string.Empty;
                oldAttributeValue = e.OldItems != null ? ((KeyValuePair<string, AttributeValue>)e.OldItems[0]).Value : null;
                oldIndex = e.OldStartingIndex;

                eventRaised = true;
            };

            // Make change to property
            EnqueueCallback(() => attributes.Remove("Test1"));

            // Wait for event to complete
            EnqueueConditional(() => eventRaised != false);

            // Test that event was appropriately fires and handled
            EnqueueCallback(() => Assert.AreEqual<string>(string.Empty, newAttributeName));
            EnqueueCallback(() => Assert.IsNull(newAttributeValue));
            EnqueueCallback(() => Assert.AreEqual<string>("Test1", oldAttributeName));
            EnqueueCallback(() => Assert.AreEqual<string>("Test Value1", oldAttributeValue.Value));
            EnqueueCallback(() => Assert.AreEqual<NotifyCollectionChangedAction>(action, NotifyCollectionChangedAction.Remove));
            EnqueueCallback(() => Assert.IsTrue(attributes.Count == 0));

            // Reset testing fields
            EnqueueCallback(() => action = NotifyCollectionChangedAction.Reset);
            EnqueueCallback(() => newAttributeName = string.Empty);
            EnqueueCallback(() => newAttributeValue = null);
            EnqueueCallback(() => newIndex = -1);
            EnqueueCallback(() => oldAttributeName = string.Empty);
            EnqueueCallback(() => oldAttributeValue = null);
            EnqueueCallback(() => oldIndex = -1);
            EnqueueCallback(() => eventRaised = false);

            EnqueueTestComplete();
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:55,代码来源:AttributeCollectionTests.cs


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