Search code examples
c#-4.0postsharp

Postsharp Include all methods except constructors


If I have an MethodInterceptionAspect how can I define it to include all methods in the class it is intercepting except for the constructors?

For example something along the following lines appears not to work...

[MyAspect(AttributeTargetMembers="regex:!.cctor|.*")]

Solution

  • You need to apply your attribute to class with AttributeTargetElements = MulticastTargets.Method. It targets methods (but not constructors).

    This should do the trick:

    [MyAspect(AttributeTargetElements = MulticastTargets.Method)]