Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

i decared a custom attribute class:

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Field|AttributeTargets.All, AllowMultiple = false)]
   public class AssemblyTypeName : System.Attribute
   {
      
       string itemName;
       public string NameOfClass
       {
           get
           {
               return itemName;
           }
       }
       public AssemblyTypeName(string nameOfClass)
       {
           itemName = nameOfClass;
       }
   }

 

 

now, just above the class that i want to use the custom attribute i place the line:

   [ AssemblyTypeName("BusinessEmployee")]

 

i read in the assembly data for the assembly that uses the custom attribute,but i cant find out how to access my custom attribute ( before i instantiate the class).it is being used to identify the class in order to see if its the one i want to create an instance of.

Edited by PlausiblyDamp
  • Leaders
Posted

You probably want to use reflection. Maybe load the assembly for reflection, find the type(s) you want to examine, and then use the Attribute.GetCustomAttribute function to load the attributes. The attribute type will need to be loaded (and not just for reflection) though in order for this to work.

 

I've never actually done this before so there may be something I've missed.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...