Home All Groups Group Topic Archive Search About

Howto: Determine within a custom attribute, the type it has been declared on?

Author
16 Mar 2007 5:36 AM
Kenneth Baltrinic
I have a custom attribute that inherits from System.Attribute and itself is
declared with the AttributeUsage( AttributeTargets.Class ) attribute.
Regarding this I have two questions.

Can I further limit my attribute to only be applicable to types that are
concrete and have a public default constructor?
Can I, from within my attribute class determine the System.Type of the class
to which it has been applied?

--Ken

Author
16 Mar 2007 5:55 PM
Oliver Sturm
Hello Kenneth,

>Can I further limit my attribute to only be applicable to types that are
>concrete and have a public default constructor?
>Can I, from within my attribute class determine the System.Type of the
>class to which it has been applied?

I don't think either of these is possible.


                Oliver Sturm
Author
16 Mar 2007 7:18 PM
Ben Voigt
"Kenneth Baltrinic" <no.direct.repl***@nowhere.xyz> wrote in message
news:OzaOaS9ZHHA.4772@TK2MSFTNGP05.phx.gbl...
>I have a custom attribute that inherits from System.Attribute and itself is
>declared with the AttributeUsage( AttributeTargets.Class ) attribute.
>Regarding this I have two questions.
>
> Can I further limit my attribute to only be applicable to types that are
> concrete and have a public default constructor?
> Can I, from within my attribute class determine the System.Type of the
> class to which it has been applied?

An attribute can accept a Type parameter to its constructor, but the caller
would have to manually specify the class it is being applied to.

Show quote
>
> --Ken
>

AddThis Social Bookmark Button