Reflection - dynamically adding custom attributes
-
Is it possible to dynamically adding custom attributes to class methods or properties? If so any examples will be appreciated.
No
I know the language. I've read a book. - _Madmatt
-
No
I know the language. I've read a book. - _Madmatt
Man, way to crush his dreams ;P
Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels) -
Is it possible to dynamically adding custom attributes to class methods or properties? If so any examples will be appreciated.
-
Is it possible to dynamically adding custom attributes to class methods or properties? If so any examples will be appreciated.
Would compiling code at runtime suffice (e.g., creating a new class with methods/properties that have the custom attributes)? That can be done.
-
This is using codedom to write code dynamically not dynamically adding an attribute to existing code. They are not equal.
I know the language. I've read a book. - _Madmatt
-
Is it possible to dynamically adding custom attributes to class methods or properties? If so any examples will be appreciated.
don't kill the pianist, but I thing I did somethings related to this. It was some time ago and I don't have that resources, but here is the catch. There was a way to specify what property "descriptor" to use for a specific class. From that class, you call the default property descriptor and modify the returned list of attributes as you wish. Sorry if the terms are not quite accurate but they may bring up someone [else?] idea about how to do this.
-
Is it possible to dynamically adding custom attributes to class methods or properties? If so any examples will be appreciated.
If it's possible to dynamically add custom attributes to a class, you'll be jumping through so many hoops to do so that perhaps a better question to ask is: "am I trying to do something I shouldn't be trying to do?" Also, by attempting to do something so far "outside the box" of .Net programming as it was intended by MS that you'll potentially be creating a maintenance problem for whoever works on the code after you. If you need to dynamically decorate a type, property, etc. with attribute-like information, perhaps a wiser design is to implement your own repository of such information (perhaps a static
Dictionary<MemberInfo, MyCustomAttribute>
, or some such). If necessary, you can initialize it from the complier-built attributes, but that should be the end of your logic's relationship with attributes. Just a thought.