views:

884

answers:

1

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
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
Well, ability to search information on the web is one of the major skills of modern software developer
aku
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
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
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
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
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
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
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
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