Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# attribute collection [duplicate]

I have a certain collection of built-in attributes (like System.Runtime.Serialization.SerializableAttribute) that I want to apply to a certain collection of classes

Is it possible to unite those attributes into one? I don't want to apply all of them to all of my classes explicitly (the attibute collection might change during the development process)

What I want is one attribute, e.g.

public class MyClassAttribute: System.Attribute { ... }

which I could apply easily to my classes

[MyClass]
public class SampleClass { ... }

and that would cause SampleClass to have Serializable attribute and others. Thanks

like image 812
Prof. Legolasov Avatar asked Jul 08 '13 11:07

Prof. Legolasov


1 Answers

No, it is not, basically. Actually, [Serializable] is particularly note-worthy because that has different treatment in the compiler - it is not written as an attribute, but as a raw flag (the runtime simply lies if you ask "does it have the [Serializable] attribute" - it checks the flag against the type, and returns what you expect to see, even though that isn't the truth).

like image 79
Marc Gravell Avatar answered Oct 13 '22 22:10

Marc Gravell