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?
+8
A:
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
aku
2008-10-01 05:18:31
I wouldn't have asked here if I hadn't exhausted my search for the answer on Google and MSDN. I wasn't quite sure what too look up. Your answer points me in all the right directions, thank you!
Fox Diller
2008-10-01 05:21:48
Well, ability to search information on the web is one of the major skills of modern software developer
aku
2008-10-01 05:24:38
Yeah, but asking the correct question in the fields of copy/pasta regurgitations of the same tutorials, it's hard to find concrete answers. Again, thank you.
Fox Diller
2008-10-01 05:25:51
The hardness of using MSDN/Google for technical questions was one of the main reasons to make StackOverflow -- questions like this should be asked here.
Alex Lyman
2008-10-01 05:30:33
In my case, google is as useful as my ability to guess the keywords needed to find the required information, which can be very tricky if I don't know exactly what are the keywords used in that particular area of interest.
alexandrul
2008-10-01 05:33:11
Some people are better at it than others aku... we'll learn :) if I was high-strung, the response would seem a bit curt.
Gishu
2008-10-01 05:33:19
Gishu, data mining is essential skill. If you can find a way through weird code, it should not be a problem to digg google
aku
2008-10-01 05:46:13
Seeing how Stackoverflow.com is aimed at being a programmers Q-) In theory, you could suggest the 'ol "use google next time..." approach to every single question posted here.
deadbug
2008-10-01 05:48:24
deadbug don't exaggerate. In this particular case Google will give you tons of useful info for a single query ".net c# custom attributes"
aku
2008-10-01 05:51:31
Well, I did use google to find out how to create my own attribute which I had completed before asking my question. Though, my problem was actually finding anything to show me how to iterate through my field attributes in my entire assembly.
Fox Diller
2008-10-01 15:24:33