Before I start, I'd like to clarify that my current understanding of AOP terminology is as follows...
- Aspects are the AOP equivalent of Classes in OOP.
- Advices are the AOP equivalent of Methods in OOP.
- Pointcuts are the AOP equivalent of 'using' code in OOP. In OOP we invoke things. In AOP we weave things. The decision of what to weave where is defined by Pointcuts.
Onto the actual question...
I have a logging aspect in PostSharp which I want to use (weave) on every method, excluding properties. Originally I was using the following on my aspect:
[MulticastAttributeUsage(MulticastTargets.Method, TargetMemberAttributes = MulticastAttributes.Instance)]
However, I found the aspect was still being woven into properties, meaning I had to perform a secondary check at runtime to preclude my code from executing on properties:
if (!methodName.StartsWith("set_") && !methodName.StartsWith("get_")) {
This is not ideal. I should be able to define this behavior in my pointcut so that I don't have to perform any runtime checking.
I have been looking into the MethodPointcut
attribute which appears to provide me with a callback to help the weaver select candidates for the advice at build time. Please can I see an example?
Assuming this does work, I am still left thinking 'Why must I hardcode Pointcuts to my Advices?'. Aspects and Advices are the definition/implementation. Pointcuts are the usage. The two should be seperate.