字段上的C#属性 [英] C# Attributes On Fields

查看:79
本文介绍了字段上的C#属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在装配体中任何地方的字段上设置属性,然后在整个装配体中反映这些字段属性,并获取/设置也附加了该属性的字段值?

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)创建针对字段 >
2)将其添加到所需字段

3)遍历程序集中定义的类型

4)对于每个类型

4a)通过它迭代f产生

4b)如果字段具有自定义属性转到步骤4c

4c)获取 set 字段的值

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

这篇关于字段上的C#属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆