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

  • Thread starter Thread starter Kenneth Baltrinic
  • Start date Start date
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
 
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
 
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.
 
Back
Top