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

K

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
 
O

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
 
B

Ben Voigt

Kenneth Baltrinic said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top