【发布时间】:2016-05-11 12:41:59
【问题描述】:
问题。有没有办法根据我的自定义属性的给定实例(例如 MyAttribute)获取 CustomAttributeData 的实例?还是反过来?
我为什么需要这个? MyAttribute 的实例包含我感兴趣的属性,而CustomAttributeData 的实例包含我感兴趣的实际构造函数参数。所以现在我实现 double工作:首先,通过调用获取MyAttribute的实例
Attribute.GetCustomAttribute(property, typeof(MyAttribute)) as MyAttribute
和秒,通过调用获取CustomAttributeData的实例
CustomAttributeData.GetCustomAttributes(property)
走过这个收藏。
P. S.我查看了this question,但没有找到所需的解决方案。
【问题讨论】:
标签: c# reflection custom-attributes system.reflection