Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法进入str1代码?
str1
[MyAttribute("str1")] class X {}
的实例Mono.Cecil.CustomAttribute.Fields为空。
Mono.Cecil.CustomAttribute.Fields
在 .NET 中使用属性时,您要么使用构造函数参数并设置一些(命名的)字段。这在元数据中以不同的方式编码,并在 Cecil 中单独结束。
Mono.Cecil.CustomAttribute.Fields 的实例为空
您正在使用的是在将构造函数参数用于自定义属性时查找字段。所以你要找的是:
type.CustomAttributes[0].ConstructorArguments[0].Value