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

instance

Glossary Item Box

Returns the value of the property for the specified instance

Syntax

Visual Basic (Declaration) 
Public Function GetValue( _
   ByVal instance As Object _
) As Object
C# 
public object GetValue( 
   object instance
)

Parameters

instance

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