Sets the specified value for the instance supplied
Syntax
Example
Library/Library.Test/TestPropertyType.cs
C# | Copy Code |
---|
a classa = new a();
classa.PropertyA = "hello";
Assert.AreEqual("hello", classa.PropertyA);
PropertyType pt = new PropertyType(classa.GetType(), "PropertyA");
Assert.AreEqual("hello", pt.GetValue(classa));
pt.SetValue(classa, "world");
Assert.AreEqual("world", pt.GetValue(classa));
Assert.AreEqual("world", classa.PropertyA);
classa.PropertyA = "hello";//set privateField back to "hello"
Assert.AreEqual("hello", classa.PropertyA);
pt = new PropertyType(classa.GetType(), "privateField");
Assert.AreEqual("hello", pt.GetValue(classa));
pt.SetValue(classa, "world");
Assert.AreEqual("world", pt.GetValue(classa));
Assert.AreEqual("world", classa.PropertyA); |
VB.NET | Copy Code |
---|
Dim classa As New a()
classa.PropertyA = "hello"
Assert.AreEqual("hello", classa.PropertyA)
Dim pt As New PropertyType(classa.[GetType](), "PropertyA")
Assert.AreEqual("hello", pt.GetValue(classa))
pt.SetValue(classa, "world")
Assert.AreEqual("world", pt.GetValue(classa))
Assert.AreEqual("world", classa.PropertyA)
classa.PropertyA = "hello"
'set privateField back to "hello"
Assert.AreEqual("hello", classa.PropertyA)
pt = New PropertyType(classa.[GetType](), "privateField")
Assert.AreEqual("hello", pt.GetValue(classa))
pt.SetValue(classa, "world")
Assert.AreEqual("world", pt.GetValue(classa))
Assert.AreEqual("world", classa.PropertyA) |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also