Re: Custom Attributes on Controls
From: Sean Hederman (usemy_at_blogentry.com)
Date: 02/17/05
- Next message: Carlos J. Quintero [.NET MVP]: "Re: Adding function to Excel"
- Previous message: Sean Hederman: "Re: Writing a windows service with a socket interface."
- In reply to: WFB: "Re: Custom Attributes on Controls"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 17 Feb 2005 16:26:48 +0200
GetFields with no parameters will not return a protected field. Use:
Me.GetType().GetFields(BindingFlags.GetField Or BindingFlags.Instance Or
BindingFlags.NonPublic)
"WFB" <x@hotmail.com> wrote in message
news:%231HgQEPFFHA.2176@TK2MSFTNGP15.phx.gbl...
> Sean,
>
> Im not sure I follow. If I have
>
> Public Class MyClass
> <MyCustomattribute()> Protected WithEvents Ctrl as MyLibrary.MyControl
>
> Sub New()
> Dim s as String
> End Sub
>
> End Class
>
> Then (in the bebugger) during the constructor try
> Me.GetType().GetFields(), no results are returned. Can you let me know
> what Im doing wrong?
>
> Thanks a lot for your help.
>
> Joe
>
> "Sean Hederman" <usemy@blogentry.com> wrote in message
> news:cuvqah$gc4$1@ctb-nnrp2.saix.net...
>> That code is not tagging a control, it's tagging a field inside another
>> object. GetType is returning the control's type, which does not have an
>> attribute on it. Consider the following:
>>
>> <FirstAttribute("Hello")> Public Class MyControl
>> End Class
>>
>> Public Class MyContainer
>> <SecondAttribute("Hello2")> Protected WithEvents SectionHeader As
>> TitleBar
>> End Class
>>
>> Now, if you used SectionHeader.GetType().GetCustomAttributes(True), it
>> would return FirstAttribute, not SecondAttribute, since FirstAttribute is
>> defined on the MyControl type. If, however you got a FieldInfo object
>> pointing to the SectionHeader field inside the MyContainerType, it's
>> GetCustomAttributes would return SecondAttribute.
>>
>> "WFB" <x@hotmail.com> wrote in message
>> news:uGU1gaDFFHA.3596@TK2MSFTNGP12.phx.gbl...
>>> At runtime -- I check in the debugger for
>>> SectionHeader.GetType().GetCustomAttributes(True) and it is not there.
>>>
>>> Thanks
>>> Joe
>>>
>>> "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message
>>> news:Ovl6WkhEFHA.2180@TK2MSFTNGP10.phx.gbl...
>>>>
>>>>>Howevr I can not see the attribute if i "tag" a control with it, such
>>>>>as; <MyAttribute("hello")> Protected WithEvents SectionHeader As
>>>>>XYZ.SalesApp.Controls.WebControls.TitleBar, I can not see the
>>>>>attribute.
>>>>
>>>>
>>>> Where are you looking for it?
>>>>
>>>>
>>>>
>>>> Mattias
>>>>
>>>> --
>>>> Mattias Sjögren [MVP] mattias @ mvps.org
>>>> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
>>>> Please reply only to the newsgroup.
>>>
>>>
>>
>>
>
>
- Next message: Carlos J. Quintero [.NET MVP]: "Re: Adding function to Excel"
- Previous message: Sean Hederman: "Re: Writing a windows service with a socket interface."
- In reply to: WFB: "Re: Custom Attributes on Controls"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|