On Aug 5, 9:46*am, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
*<chrisbarb...@gmail.comwrote:
Can anyone help??
How can i get the string representation of a property?
For example if I have a Client object that has a FirstName property,
how in code can I get "FirstName" from Client.FirstName ?
You can't. If you've got the value returned from Client.FirstName,
that's just a reference to a string. You could have got it in any
number of ways.
What problem are you actually trying to solve? There's probably a
better way.
--
Jon Skeet - <sk...@pobox.com>
Web site:http://www.pobox.com/~skeet*
Blog:http://www.msmvps.com/jon.skeet
C# in Depth:http://csharpindepth.com
On Aug 5, 9:46 am, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
<chrisbarb...@gmail.comwrote:
Can anyone help??
How can i get the string representation of a property?
For example if I have a Client object that has a FirstName property,
how in code can I get "FirstName" from Client.FirstName ?
You can't. If you've got the value returned from Client.FirstName,
that's just a reference to a string. You could have got it in any
number of ways.
What problem are you actually trying to solve? There's probably a
better way.
--
Jon Skeet - <sk...@pobox.com>
Web site:http://www.pobox.com/~skeet
Blog:http://www.msmvps.com/jon.skeet
C# in Depth:http://csharpindepth.com
Thanks for helping. My situation is this:
Public Sub test()
Dim desc As String = Description("Forname")
End Sub
Private Function Description(ByVal val As String) As String
' I know the class
Dim t As New T()
' create a property info for this property of the class
Dim pi As PropertyInfo = t.GetType.GetProperty(val)
' get my custom description attribute
Dim atts As DescriptionAttribute() =
DirectCast(pi.GetCustomAttributes(GetType(Descript ionAttribute),
False), DescriptionAttribute())
' return it
If atts IsNot Nothing Then Return atts(0).Description
Return "No Description"
End Function
What i desparately want to avoid is passing the string:
Description("Forname") but rather pass Client.Forename to the
function, which will realise Forename is the property to interigate.
Does this make sense? any ideas?