Custom attributes on property

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
 
A

Armin Zingler

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
 
W

Watty

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( _
 
A

Armin Zingler

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
 
W

Watty

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top