本文整理汇总了C#中Accessor.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Accessor.Clear方法的具体用法?C# Accessor.Clear怎么用?C# Accessor.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Accessor
的用法示例。
在下文中一共展示了Accessor.Clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDictionary
public void TestDictionary()
{
TestClass tc = new TestClass();
Accessor<TestClass> tca = new Accessor<TestClass>(tc, supportsNew: true);
KeyValuePair<string, object> kvp1 = new KeyValuePair<string, object>("Key1", 123);
KeyValuePair<string, object> kvp2 = new KeyValuePair<string, object>("Key2", 456);
KeyValuePair<string, object> kvp3 = new KeyValuePair<string, object>("Key3", 789);
Assert.AreEqual(4, tca.Count);
tca.Add("PublicAutoProperty", "Value");
Assert.AreEqual(4, tca.Count);
Assert.AreEqual("Value", tc.PublicAutoProperty);
tca.Add(new KeyValuePair<string, object>("PublicAutoProperty", "Value 2"));
Assert.AreEqual(4, tca.Count);
Assert.AreEqual("Value 2", tc.PublicAutoProperty);
tca.Add(kvp1.Key, kvp1.Value);
tca.Add(kvp2);
tca.Add(kvp3);
Assert.AreEqual(7, tca.Count);
Assert.AreEqual(kvp1.Value, tca[kvp1.Key]);
Assert.AreEqual(kvp2.Value, tca[kvp2.Key]);
Assert.AreEqual(kvp3.Value, tca[kvp3.Key]);
Assert.IsTrue(tca.ContainsKey(kvp1.Key));
Assert.IsTrue(tca.Contains(kvp2));
Assert.IsTrue(tca.ContainsKey(kvp3.Key));
tca.Remove(kvp1.Key);
Assert.AreEqual(6, tca.Count);
Assert.IsFalse(tca.ContainsKey(kvp1.Key));
tca.Remove(kvp2);
Assert.AreEqual(5, tca.Count);
Assert.IsFalse(tca.ContainsKey(kvp2.Key));
tca.Clear(false);
Assert.AreEqual(4, tca.Count);
Assert.IsFalse(tca.ContainsKey(kvp3.Key));
}