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