What's wrong with this aspect

I want this to be called when the property is set. Why doesn't it work?

[DirtyTrackingAttribute(AttributeTargetElements =
   PostSharp.Extensibility.MulticastTargets.Property)]
class Program
{

    public static string Test { get; set; }

    static void Main(string[] args)
    {
        TestIt();
        Test = "foo";
        Console.ReadKey();
    }

    private static void TestIt()
    {
      Console.WriteLine("Real method called");
    }
}

[Serializable]
public class DirtyTrackingAttribute : OnMethodInvocationAspect
{
    public override void OnInvocation(MethodInvocationEventArgs eventArgs)
    {
        Console.WriteLine("Property invoked");
        eventArgs.Proceed();
    }
}

      

0


a source to share


1 answer


If you only want the aspect to be applied to property setters, you can filter the method name with the "set _ *" expression:

[DirtyTrackingAttribute(AttributeTargetMembers="set_*")]

      



PostSharp 1. * does not explicitly support properties; Property accessors are treated as simple methods.

+1


a source







All Articles