Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Attributes On Fields

How do I set an attribute on a field anywhere in my assembly, then reflect on those field attributes in my entire assembly and get/set the field values that the attribute is attached too?

like image 469
Fox Diller Avatar asked Oct 01 '08 05:10

Fox Diller


1 Answers

1) Create custom attribute targeted for fields
2) Add it to desired fields
3) Iterate through types defined in your assembly
4) For each type:
4a) iterate through it's fields
4b) if field has your custom attribute go to step 4c
4c) get or set values of field

like image 120
aku Avatar answered Oct 25 '22 09:10

aku