本文整理汇总了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);
}
示例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);
}
示例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();
}