Home All Groups Group Topic Archive Search About

Custom attributes on property

Author
4 Jun 2009 4:18 PM
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

Author
4 Jun 2009 5:50 PM
Armin Zingler
Watty wrote:
Show quoteHide quote
> 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
Author
4 Jun 2009 8:09 PM
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( _
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
>
Author
4 Jun 2009 9:47 PM
Armin Zingler
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
Author
5 Jun 2009 8:06 AM
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


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
>
>
Author
5 Jun 2009 10:25 AM
Armin Zingler
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