Custom attribute that, when applied to a method, intercepts all calls to this method.
The aspect implementation receives a delegate to the called method and the array of
arguments.
Namespace:
PostSharp.LaosAssembly: PostSharp.Laos (in PostSharp.Laos.dll)
Syntax
| Visual Basic (Declaration) |
|---|
<SerializableAttribute> _ <AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Method Or AttributeTargets.Property Or AttributeTargets.Event, AllowMultiple := False, _ Inherited := False)> _ <MulticastAttributeUsageAttribute(MulticastTargets.Method, AllowExternalAssemblies := True, _ AllowMultiple := True)> _ Public MustInherit Class OnMethodInvocationAspect _ Inherits LaosMethodLevelAspect _ Implements IOnMethodInvocationAspect, ILaosMethodLevelAspect, ILaosWeavableAspect, ILaosAspect |
| C# |
|---|
[SerializableAttribute] [AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Event, AllowMultiple = false, Inherited = false)] [MulticastAttributeUsageAttribute(MulticastTargets.Method, AllowExternalAssemblies = true, AllowMultiple = true)] public abstract class OnMethodInvocationAspect : LaosMethodLevelAspect, IOnMethodInvocationAspect, ILaosMethodLevelAspect, ILaosWeavableAspect, ILaosAspect |
| Visual C++ |
|---|
[SerializableAttribute] [AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Method|AttributeTargets::Property|AttributeTargets::Event, AllowMultiple = false, Inherited = false)] [MulticastAttributeUsageAttribute(MulticastTargets::Method, AllowExternalAssemblies = true, AllowMultiple = true)] public ref class OnMethodInvocationAspect abstract : public LaosMethodLevelAspect, IOnMethodInvocationAspect, ILaosMethodLevelAspect, ILaosWeavableAspect, ILaosAspect |
Remarks
This aspect creates a stub for each method to which it is applied. The stub instantiates a delegate to the original method, then it calls the OnInvocation(MethodInvocationEventArgs) method of the aspect implementation and passes the delegate as a part of the event arguments (MethodInvocationEventArgs).
This aspect can be woven at two location:
| Call Site | Each call instruction to the aspected method is replaced by a call to our stub. This allows to intercept calls to methods defined in another assembly than the current one. However, since it does not modify the target method, calls from other assemblies will not be intercepted. This weaving site is generally not useful when applied to methods defined in the current assembly. |
| Target Site | The method itself is modified, so the aspect will be applied even when the method will be called from a different assembly. Actually, the body of the original method is moved into a new method, and the original method is replaced by the stub. That is, the original method becomes the stub and the new method contain the original method body, By default, all custom attributes defined on the original method are moved to the new method. The ImplementationBoundAttributeAttribute custom attribute controls which custom attribute should stay on the original method. |
The default behavior is to use the Call Site strategy for methods defined in an external assembly, and Target Site for methods defined in the current assembly. This behavior can be changed by overwriting the GetOptions()()() method.
Inheritance Hierarchy
System..::.Object
System..::.Attribute
PostSharp.Extensibility..::.MulticastAttribute
PostSharp.Laos..::.LaosAspect
PostSharp.Laos..::.LaosWeavableAspect
PostSharp.Laos..::.LaosMethodLevelAspect
PostSharp.Laos..::.OnMethodInvocationAspect
System..::.Attribute
PostSharp.Extensibility..::.MulticastAttribute
PostSharp.Laos..::.LaosAspect
PostSharp.Laos..::.LaosWeavableAspect
PostSharp.Laos..::.LaosMethodLevelAspect
PostSharp.Laos..::.OnMethodInvocationAspect