|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Custom attributes on propertyI 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 wrote:
Show quoteHide quote > Hi All Dim atts = GetType(Client).GetProperty( _> > 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 "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( _ Show quoteHide quote > "AddressLine1", Reflection.BindingFlags.Instance _ > Or Reflection.BindingFlags.Public).GetCustomAttributes(False) "Armin Zingler" wrote: > Watty wrote: > > 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 > Watty wrote:
> Hi Armin Method names don't exist when the application runs. Method calls are > > Thanks for that but was trying to get away from having the method > name as a string. > > GetMyAttributes( x.AddressLine1 ) 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 Show quoteHide quote "Armin Zingler" wrote: > Watty wrote: > > 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 > > I don't see the relation to using Reflection at run time.
Armin Watty wrote: Show quoteHide quote > 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 > > > "Armin Zingler" wrote: > >> Watty wrote: >>> 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 |
|||||||||||||||||||||||