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


C# AttributeCollection.Update方法代码示例

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


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

示例1: TestUpdatingAttribute

        public void TestUpdatingAttribute()
        {
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue newAttributeValue = new AttributeValue("Test Value");

            // Add attribute and attribute value
            attributes.Add("Test", newAttributeValue);

            Assert.AreEqual<string>(newAttributeValue.Value, attributes["Test"].Value);

            AttributeValue updatedAttributeValue = new AttributeValue("New Test Value");

            // Add attribute and attribute value
            attributes.Update("Test", updatedAttributeValue);

            // Ensure that the attribute has an updated value
            Assert.AreEqual<string>(updatedAttributeValue.Value, attributes["Test"].Value);
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:18,代码来源:AttributeCollectionTests.cs

示例2: TestUpdatingIdenticalAttribute

        public void TestUpdatingIdenticalAttribute()
        {
            AttributeCollection attributes = new AttributeCollection();
            AttributeValue newAttributeValue = new AttributeValue("Test Value");

            // Add attribute and attribute value
            attributes.Add("Test", newAttributeValue);

            Assert.AreEqual<string>(newAttributeValue.Value, attributes["Test"].Value);

            // Try updating the attribute with the same value
            attributes.Update("Test", newAttributeValue);

            // Ensure that the attribute has an updated value
            Assert.AreEqual<string>(newAttributeValue.Value, attributes["Test"].Value);
        }
开发者ID:senfo,项目名称:snaglV2,代码行数:16,代码来源:AttributeCollectionTests.cs

示例3: TestCollectionChangedWithUpdatee

        public void TestCollectionChangedWithUpdatee()
        {
            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.Update("Test1", new AttributeValue("Updated Value1")));

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

            // Test that event was appropriately fires and handled
            EnqueueCallback(() => Assert.AreEqual<string>("Test1", oldAttributeName));
            EnqueueCallback(() => Assert.AreEqual<string>("Test1", newAttributeName));
            EnqueueCallback(() => Assert.AreEqual<string>("Test Value1", oldAttributeValue.Value));
            EnqueueCallback(() => Assert.AreEqual<string>("Updated Value1", newAttributeValue.Value));
            EnqueueCallback(() => Assert.AreEqual<NotifyCollectionChangedAction>(action, NotifyCollectionChangedAction.Replace));

            // 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,代码行数:54,代码来源:AttributeCollectionTests.cs


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