CSharpTest.Net
SetValue Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Reflection Namespace > PropertyType Class : SetValue Method

instance
value

Glossary Item Box

Sets the specified value for the instance supplied

Syntax

Visual Basic (Declaration) 
Public Sub SetValue( _
   ByVal instance As Object, _
   ByVal value As Object _
) 
C# 
public void SetValue( 
   object instance,
   object value
)

Parameters

instance
value

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.NETCopy 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

Generated with Document! X 2011 by Innovasys