Mark Century
New member
- Joined
- Jun 24, 2011
- Messages
- 4
- Programming Experience
- 10+
How can I get a string with the name of a property at run time?
Obviously using GetProperty, as shown below, is NOT a solution since it requires knowing the property name to begin with:
Imports System.Reflection
Module Module1
Public Class Country
Public Property Capital As String
Public Property Population As Long
End Class
Public Sub ShowName()
Dim Nation As New Country
Dim PropertyName As String = Nation.GetType().GetProperty("Capital").Name
Console.WriteLine(PropertyName)
End Sub
End Module
What I want is to get the name from an instance (Nation.Capital for example) or from the type (Country.Capital).
Thanks
Mark
Obviously using GetProperty, as shown below, is NOT a solution since it requires knowing the property name to begin with:
Imports System.Reflection
Module Module1
Public Class Country
Public Property Capital As String
Public Property Population As Long
End Class
Public Sub ShowName()
Dim Nation As New Country
Dim PropertyName As String = Nation.GetType().GetProperty("Capital").Name
Console.WriteLine(PropertyName)
End Sub
End Module
What I want is to get the name from an instance (Nation.Capital for example) or from the type (Country.Capital).
Thanks
Mark