jeudi 10 janvier 2019

Is there a way to directly access the attributes of a property from the getter or setter?

I have a property that looks like this:

<DataElement(0, 4)>
Private Property RiffId As String
   Get
      Dim mb As MethodBase = MethodBase.GetCurrentMethod()
      Dim de As DataElementAttribute = mb.GetCustomAttribute(Of DataElementAttribute)()
      ...
  End Get
  Set(value As String)
     ...
  End Set
End Property

(This project is VB but C# answers are perfectly welcome.)

The variable de contains null/Nothing because the attribute applies to the property as a whole, not to the getter, which is what the mb variable contains. Is there a convenient and direct way to get to the "parent" method base without getting the name of the getter, stripping off the leading "get_", and searching the properties of the class to get the attributes of the property? I don't see one but perhaps I'm overlooking it.





Aucun commentaire:

Enregistrer un commentaire