如何在 Cecil 中获取程序集的属性值
有没有办法在代码中获取 str1
?
[MyAttribute("str1")]
class X {}
Mono.Cecil.CustomAttribute.Fields
的实例为空。
Is there a way to get str1
in code ?
[MyAttribute("str1")]
class X {}
The instance of Mono.Cecil.CustomAttribute.Fields
is empty.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 .NET 中使用属性时,您可以使用构造函数参数并设置一些(命名)字段。这在元数据中以不同的方式编码,并在 Cecil 中单独结束。
构造函数参数用于自定义属性时,您使用的是查找字段。所以你要找的是:
When using attributes in .NET you are either using the constructor parameters and setting some (named) fields. This is encoded differently in the metadata and ends up separately in Cecil.
What you're using is looking for fields when the constructor arguments were used for the custom attribute. So what you're looking for is: