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

Glossary Item Box

Returns the name of the property/field

Syntax

Visual Basic (Declaration) 
Public ReadOnly Property Name As String
C# 
public string Name {get;}

Example

Library/Library.Test/TestPropertyValue.cs

C#Copy Code
b obj = new b();
a obja = new a();
obj.publicField = obja;
obja.PropertyA = "test";

PropertyValue pt;
//Any of the following formats can be used
pt = PropertyValue.TraverseProperties(obj, "publicField.PropertyA.Length");
Assert.AreEqual("Length", pt.Name);
Assert.AreEqual(typeof(int), pt.Type);
pt = PropertyValue.TraverseProperties(obj, "publicField", "PropertyA", "Length");
Assert.AreEqual("Length", pt.Name);
Assert.AreEqual(typeof(int), pt.Type);
pt = PropertyValue.TraverseProperties(obj, "publicField.PropertyA", "Length");
Assert.AreEqual("Length", pt.Name);
Assert.AreEqual(typeof(int), pt.Type);
pt = PropertyValue.TraverseProperties(obj, "publicField/PropertyA\\Length");
Assert.AreEqual("Length", pt.Name);
Assert.AreEqual(typeof(int), pt.Type);
pt = PropertyValue.TraverseProperties(obj, "publicField\\PropertyA", "Length");
Assert.AreEqual("Length", pt.Name);
Assert.AreEqual(typeof(int), pt.Type);
            
pt = PropertyValue.TraverseProperties(obj, "publicField/PropertyA");
Assert.AreEqual("PropertyA", pt.Name);
Assert.AreEqual(typeof(string), pt.Type);

Assert.AreEqual("test", pt.Value);
pt.Value = "b";
Assert.AreEqual("b", pt.Value);
VB.NETCopy Code
Dim obj As New b()
Dim obja As New a()
obj.publicField = obja
obja.PropertyA = "test"

Dim pt As PropertyValue
'Any of the following formats can be used
pt = PropertyValue.TraverseProperties(obj, "publicField.PropertyA.Length")
Assert.AreEqual("Length", pt.Name)
Assert.AreEqual(GetType(Integer), pt.Type)
pt = PropertyValue.TraverseProperties(obj, "publicField", "PropertyA", "Length")
Assert.AreEqual("Length", pt.Name)
Assert.AreEqual(GetType(Integer), pt.Type)
pt = PropertyValue.TraverseProperties(obj, "publicField.PropertyA", "Length")
Assert.AreEqual("Length", pt.Name)
Assert.AreEqual(GetType(Integer), pt.Type)
pt = PropertyValue.TraverseProperties(obj, "publicField/PropertyA\Length")
Assert.AreEqual("Length", pt.Name)
Assert.AreEqual(GetType(Integer), pt.Type)
pt = PropertyValue.TraverseProperties(obj, "publicField\PropertyA", "Length")
Assert.AreEqual("Length", pt.Name)
Assert.AreEqual(GetType(Integer), pt.Type)

pt = PropertyValue.TraverseProperties(obj, "publicField/PropertyA")
Assert.AreEqual("PropertyA", pt.Name)
Assert.AreEqual(GetType(String), pt.Type)

Assert.AreEqual("test", pt.Value)
pt.Value = "b"
Assert.AreEqual("b", pt.Value)

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys