Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically add an attribute to a method or parameter

I can use TypeDescriptor.AddAttributes to add an attribute to a type in runtime. How do I do the same for a method and parameter? (maybe 2 separate questions...)

like image 594
MatteS Avatar asked Mar 07 '10 19:03

MatteS


1 Answers

TypeDescriptor.AddAttributes only affects a very specific use-case; i.e. from within System.ComponentModel. For the rest of reflection, it knows nothing about the extra attribute. And indeed, System.ComponentModel doesn't really apply to methods or parameters.

So in short; you can't. You will need to store this information somewhere else (bespoke), or add it at compile-time.

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

Marc Gravell