Custom attributes on property

  • Thread starter Thread starter Watty
  • Start date Start date
W

Watty

Hi All

I have a class with a number of methods like below which have attributes,
now I would love to be able to do something like below, help would be really
appreciated.

Regards
Paul

Dim x As New Client
Dim y = GetMyAttributes( x.AddressLine1 )

<Column(Storage:="_AddressLine1", DbType:="NVarChar(100)",
UpdateCheck:=UpdateCheck.Never), _
DataMember(Order:=13)> _
Public Property AddressLine1() As String
Get
Return Me._AddressLine1
End Get
Set(ByVal value As String)
If (String.Equals(Me._AddressLine1, value) = False) Then
Me._AddressLine1 = value
End If
End Set
End Property
 
Watty said:
Hi All

I have a class with a number of methods like below which have
attributes, now I would love to be able to do something like below,
help would be really appreciated.

Regards
Paul

Dim x As New Client
Dim y = GetMyAttributes( x.AddressLine1 )

<Column(Storage:="_AddressLine1", DbType:="NVarChar(100)",
UpdateCheck:=UpdateCheck.Never), _
DataMember(Order:=13)> _
Public Property AddressLine1() As String
Get
Return Me._AddressLine1
End Get
Set(ByVal value As String)
If (String.Equals(Me._AddressLine1, value) = False) Then
Me._AddressLine1 = value
End If
End Set
End Property


Dim atts = GetType(Client).GetProperty( _
"AddressLine1", Reflection.BindingFlags.Instance _
Or Reflection.BindingFlags.Public).GetCustomAttributes(False)



Armin
 
Hi Armin

Thanks for that but was trying to get away from having the method name as a
string.

GetMyAttributes( x.AddressLine1 )

Regards
Paul

Dim atts = GetType(Client).GetProperty( _
 
Watty said:
Hi Armin

Thanks for that but was trying to get away from having the method
name as a string.

GetMyAttributes( x.AddressLine1 )

Method names don't exist when the application runs. Method calls are
resolved to addresses.

You only get these infos via reflection. You need a String for this purpose.



Armin
 
Hi

Thanks or your thoughts but I am thinking that this must be possible, in my
original post I copied aproperty method from the linq autogenerated code my
database. Now when Linq creates the sql it looks a what columns you have
selected and does the right thing.

dim x= from c in clients _
where c.ClientId = 1 _
Select c.ClientId, c.Address1
 
Back
Top