本文整理匯總了C#中Accessor.Add方法的典型用法代碼示例。如果您正苦於以下問題:C# Accessor.Add方法的具體用法?C# Accessor.Add怎麽用?C# Accessor.Add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Accessor
的用法示例。
在下文中一共展示了Accessor.Add方法的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));
}