Results 1 to 4 of 4

Thread: Attributes - Can they know what type they are applied to?

  1. #1

    Thread Starter
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616

    Attributes - Can they know what type they are applied to?

    I have a custom class that inherits from System.ComponentModel.CategoryAttribute and I want to override the GetLocalizedString function to return a localised category other than the standard ones (Appearance, Behaviour, Data etc.)

    Is it possible for an attribute to get the type name of the thing it is applied to? The reason being that the resourcemanager that returns the description and category attribute needs to know which component type it is being called to return the localised string for.

    Thanks in advance,
    Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    not sure if this helps, but have you tried Type.IsSubClassOf ?
    eg:
    VB Code:
    1. [COLOR=BLUE]Dim[/COLOR] objType [COLOR=BLUE]As[/COLOR] Type() = Reflection.Assembly.GetExecutingAssembly.GetTypes()
    2.     [COLOR=BLUE]Dim[/COLOR] tp [COLOR=BLUE]As[/COLOR] Type
    3.  
    4.     [COLOR=BLUE]For[/COLOR] [COLOR=BLUE]Each[/COLOR] tp [COLOR=BLUE]In[/COLOR] objType
    5.         [COLOR=BLUE]If[/COLOR] tp.IsSubclassOf([COLOR=BLUE]GetType[/COLOR](Form)) [COLOR=BLUE]Then
    6. [/COLOR]            MessageBox.Show(tp.Name)
    7.         [COLOR=BLUE]End[/COLOR] [COLOR=BLUE]If
    8. [/COLOR]    [COLOR=BLUE]Next[/COLOR]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I haven't found a way to do this yet either but would be interested in a way to do it.

    The trouble with that, dynamic_sysop, is that the type would be the attribute instead of the object it is applied to. I think he (and I) want the type of the object that the attribute is used on.

  4. #4

    Thread Starter
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    I think he (and I) want the type of the object that the attribute is used on.
    That is correct - thereby using the component's resource file to hold the descriptions and category attributes that need to be localised.
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width