I've looked around for discussion on this topic, but wasn't able to find it.
I am trying to retrieve the Attributes of a class's property specifically.
So for example. Let's say I have a class called "Employee", and a custom attribute called CustomLabelAttribute with a string value. What would I need to do to retrieve the value of CustomLabelAttribute for Employee.FirstName specifically? I assume I will need to use reflection, but it's kind of new to me, and I've just recently started using it on any level.
Thanks for your help!
I am trying to retrieve the Attributes of a class's property specifically.
So for example. Let's say I have a class called "Employee", and a custom attribute called CustomLabelAttribute with a string value. What would I need to do to retrieve the value of CustomLabelAttribute for Employee.FirstName specifically? I assume I will need to use reflection, but it's kind of new to me, and I've just recently started using it on any level.
Thanks for your help!
VB.NET:
Public Class Employee
Private m_FirstName As String
<CustomLabel(value:="Employee's First Name")> _
Public Property FirstName() As String
Get
Return m_FirstName
End Get
Set(ByVal value As String)
m_FirstName = value
End Set
End Property
Private m_MiddleName As String
Public Property MiddleName() As String
Get
Return m_MiddleName
End Get
Set(ByVal value As String)
m_MiddleName = value
End Set
End Property
Private m_LastName As String
Public Property LastName() As String
Get
Return m_LastName
End Get
Set(ByVal value As String)
m_LastName = value
End Set
End Property
VB.NET:
<AttributeUsage(AttributeTargets.All, AllowMultiple:=True, Inherited:=True)> _
Public Class CustomLabelAttribute
Inherits Attribute
Public Sub New()
End Sub
Private m_Value As String
Public Property Value() As String
Get
Return m_Value
End Get
Set(ByVal value As String)
m_Value = value
End Set
End Property
End Class