C# Attributes On Fields

℡╲_俬逩灬. 提交于 2019-11-29 07:31:28

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/156304/c-sharp-attributes-on-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!