Base class for all aspects applied on methods.
Inheritance
Implements
Namespace: PostSharp.Aspects
Assembly: PostSharp.dll
Syntax
[MulticastAttributeUsage(MulticastTargets.Method|MulticastTargets.InstanceConstructor|MulticastTargets.StaticConstructor)]
[AttributeUsage(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Event, AllowMultiple = true)]
[Serializer(null)]
public abstract class MethodLevelAspect : Aspect, IMethodLevelAspect, IAspect, IMethodLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotationRemarks
note
This class does not provide any advice. You may derive your aspect class from a Developing Simple Aspects, or build a Developing Member-Level Aspects or a Developing Type- and Assembly-Level Aspects with advice methods.
An aspect derived from this class can declare the following advices. Without a pointcut, or with SelfPointcut, they apply to the method or constructor to which the aspect is applied:
- the method boundary advices OnMethodEntryAdvice, OnMethodSuccessAdvice, OnMethodExceptionAdvice, OnMethodExitAdvice, OnMethodYieldAdvice and OnMethodResumeAdvice, on methods and constructors;
- the method interception advices OnMethodInvokeAdvice and OnMethodInvokeAsyncAdvice, on methods only.
A LocationValidationAdvice validates the parameters or the return value of the method when a MethodPointcut selects them. IntroduceMemberAttribute introduces members into the declaring type of the target. IntroduceInterfaceAttribute and ImportMemberAttribute require an instance-scoped aspect (IInstanceScopedAspect).
note
All classes implementing IAspect should typically be marked as serializable using the SerializableAttribute or PSerializableAttribute custom attribute. Fields that are only used at runtime (and unknown at compile-time) should be carefully marked with the NonSerializedAttribute or PNonSerializedAttribute custom attribute. When another aspect serializer (such as MsilAspectSerializer) is used, it is not necessary to mark the aspect class as serializable. For more information, see Understanding Aspect Serialization.
Constructors
| Name | Description |
|---|---|
| MethodLevelAspect() |
Methods
| Name | Description |
|---|---|
| CompileTimeInitialize(MethodBase, AspectInfo) | Method invoked at build time to initialize the instance fields of the current aspect. This method is invoked before any other build-time method. |
| CompileTimeValidate(object) | Method invoked at build time to ensure that the aspect has been applied to the right target. |
| CompileTimeValidate(MethodBase) | Method invoked at build time to ensure that the aspect has been applied to the right target. |
| RuntimeInitialize(MethodBase) | Initializes the current aspect. |
| SetAspectConfiguration(AspectConfiguration, object) | Method invoked at build time to set up an AspectConfiguration object according to the current Aspect instance and a specified target element of the current aspect. |
| SetAspectConfiguration(AspectConfiguration, MethodBase) | Method invoked at build time to set up an AspectConfiguration object according to the current Aspect instance and a specified target element of the current aspect. |