AttributeUsage question

  • Thread starter Thread starter Henrik Dahl
  • Start date Start date
H

Henrik Dahl

Hello!

I'm making my own attribute. I've observed that the AttributeUsage attribute
may only be applied to classes which derive from System.Attribute. How do I
make my attribute in a resembling way, so it may only be applied to classes
which implement a certain interface?


Best regards,

Henrik Dahl
 
I'm making my own attribute. I've observed that the AttributeUsage attribute
may only be applied to classes which derive from System.Attribute. How do I
make my attribute in a resembling way, so it may only be applied to classes
which implement a certain interface?

You can't. AttributeUsage gets special treatment from the compiler.



Mattias
 
OK.

Do you know if it's possible, for a specific instance of an attribute, to
figure out what it's actually attributing (execpt e.g. reflection driven
traversal in some exhaustive way of course)?


Best regards,

Henrik Dahl
 
Do you know if it's possible, for a specific instance of an attribute, to
figure out what it's actually attributing (execpt e.g. reflection driven
traversal in some exhaustive way of course)?

No it isn't, unless you pass it that information.



Mattias
 
Thank you again!

I think it would be rather convenient with a read only property of
System.Attribute for giving this.


Best regards,

Henrik Dahl
 
Back
Top