PC Review


Reply
Thread Tools Rate Thread

Custom attribute applying another attribute

 
 
Andrew Roberts
Guest
Posts: n/a
 
      2nd Sep 2003
Does anyone know is it possible to create a custom attribute, say
CustomProgIdAttribtute
That when applied to a class will also apply another attribute to it, say
ProgIdAttribute
What I want is to create a custom ProgId attribute that takes two strings and then creates the string for the ProgIdAttribute and applies it.
I thought of derivation but this won't work for several reasons especialy due to the fact that the attributes are all sealed.
Any ideas? Can you programaticaly set an attribute onto a target from the code of another that is applied to that target?

--
Composed with Newz Crawler 1.5 http://www.newzcrawler.com/
 
Reply With Quote
 
 
 
 
Richard Grimes [MVP]
Guest
Posts: n/a
 
      4th Sep 2003
Andrew Roberts wrote:
> Does anyone know is it possible to create a custom attribute, say
> CustomProgIdAttribtute
> That when applied to a class will also apply another attribute to it,
> say
> ProgIdAttribute
> What I want is to create a custom ProgId attribute that takes two
> strings and then creates the string for the ProgIdAttribute and
> applies it. I thought of derivation but this won't work for several
> reasons especialy due to the fact that the attributes are all sealed.
> Any ideas? Can you programaticaly set an attribute onto a target
> from the code of another that is applied to that target?


Not really.

Attributes are read by the compiler which checks for real attributes (like
DllImport and Serializable) and custom attributes (like ProgId) and then
adds them to the metadata of the type. (Real attributes will have an IL
attribute, custom attributes are serialized and applied using the .custom
directive.) If you use the Rotor C# compiler you have the source code which
you can use to interpret your attribute and add the [ProgId] attribute
accordingly, but it seems like a lot of effort.

The other thing you can do is use the classes in System.Reflection.Emit and
create your assembly. However, that is even more effort because you'll have
to generate the IL with some code.

Richard
--
my email (E-Mail Removed) is encrypted with ROT13 (www.rot13.org)


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Attribute 'Title' is not a valid attribute of element 'ProviderWebPart' etc.. rote Microsoft ASP .NET 5 29th Oct 2008 04:55 AM
Attribute 'ms_2d_layout' is not a valid attribute of element 'table' CdnRebel Microsoft ASP .NET 4 4th Jul 2007 07:56 PM
Attribute 'onchange' is not a valid attribute of element 'TextBox' Joe Kovac Microsoft ASP .NET 2 2nd May 2007 02:11 PM
Validation (XHTML 1.0 Transitional): Attribute 'height' is not a valid attribute of element 'table' perspolis Microsoft ASP .NET 1 23rd Jan 2007 07:57 AM
Validation (XHTML 1.0 Transitional): Attribute 'leftmargin' is not a valid attribute of element 'body'. anonymous Microsoft ASP .NET 1 2nd Aug 2006 09:05 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:47 AM.