views:

57

answers:

1

Hello. I am using Cecil to try to read my attributes properties:

[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) {
}

...

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

This is, I'd like this last block of code to check whenever the attribute applied to Main, for example, has MethodMessages set to true or false. From what I've seen, it seems like both attributes.Fields.Count and attributes.Properties.Count is set to 0. Why is it?

Thanks

+1  A: 

Should work fine through accessing Properties collection by indexer.

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

Just compiled and checked it.

Oleg I.