I have an existing C# class that I cannot modify, but only use it.
By example:
public class Test {}
I would like to add dynamically an attribute (MyAttribute) to this class Test, like:
[MyAttribute(TestMode)]
public class Test {}
Is it possible in C# and how?
Note: of course, I can derive from this Test class and add declaratively the attribute, but it means to create a new class, and I’d like to avoid it.
Attributes are compiled into metadata and cannot be added at runtime.
http://msdn.microsoft.com/en-en/library/z0w1kczw(v=vs.80).aspx