C# Cecil-获取已定义的属性

C# Cecil-获取已定义的属性,c#,.net,vb.net,reflection,mono.cecil,C#,.net,Vb.net,Reflection,Mono.cecil,我正在使用Cecil尝试读取我的属性: [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] public sealed class TraceMethodAttribute : Attribute { public TraceMethodAttribute() { MethodStart = true; MethodReturn = true

我正在使用Cecil尝试读取我的属性:

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public sealed class TraceMethodAttribute : Attribute {
    public TraceMethodAttribute() {
        MethodStart = true;
        MethodReturn = true;
        MethodMessages = true;
    }

    public bool MethodStart { get; set; }
    public bool MethodReturn { get; set; }
    public bool MethodMessages { get; set; }
}

[TraceMethod(MethodMessages = false)]
static void Main(string[] args) {
}

这就是,我希望在应用于Main的属性将MethodMessages设置为true或false时检查最后一段代码。据我所见,attributes.Fields.Count和attributes.Properties.Count似乎都设置为0。为什么


谢谢

通过索引器访问属性集合应该可以很好地工作

if (attribute.Constructor.DeclaringType.FullName == typeof(TraceMethodAttribute).FullName) {         
  if ((bool)attribute.Properties["MethodMessages"] == true) {
        EditMethodStart(assembly, method);
  }

刚刚编译并检查过。

我不知道API是否自2010年以来发生了更改,但当前版本不接受索引器的字符串参数。。。
if (attribute.Constructor.DeclaringType.FullName == typeof(TraceMethodAttribute).FullName) {         
  if ((bool)attribute.Properties["MethodMessages"] == true) {
        EditMethodStart(assembly, method);
  }