Open sandboxFocus

Class TypeLevelAspect

Base class for all aspects applied on types.

Namespace: PostSharp.Aspects
Assembly: PostSharp.dll
Syntax
[MulticastAttributeUsage(MulticastTargets.Class|MulticastTargets.Struct|MulticastTargets.Interface, AllowExternalAssemblies = false, AllowMultiple = true, PersistMetaData = false)]
[AttributeUsage(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Interface, AllowMultiple = true)]
[Serializer(null)]
public abstract class TypeLevelAspect : Aspect, ITypeLevelAspect, IAspect, ITypeLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation
Remarks

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.

Developing Member-Level Aspects Developing Type- and Assembly-Level Aspects

An advice of an aspect derived from this class cannot apply to the type itself, so an advice that targets members needs a pointcut. MulticastPointcut and SignaturePointcut select among the members declared in the target type; MethodPointcut can also select parameters and return values. The advices are:

The following advices need no pointcut. IntroduceMemberAttribute introduces members into the target type, and OnInstanceConstructedAdvice runs when an instance of the target type has been constructed. IntroduceInterfaceAttribute and ImportMemberAttribute require an instance-scoped aspect: derive from InstanceLevelAspect.


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.

Understanding Aspect Serialization

Constructors

Name Description
TypeLevelAspect()

Methods

Name Description
CompileTimeInitialize(Type, 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(Type)

Method invoked at build time to ensure that the aspect has been applied to the right target.

RuntimeInitialize(Type)

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, Type)

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.

See Also