Metalama 1.0 / / Metalama Documentation / Post­Sharp API Migration / Post­Sharp.​Aspects

Namespace PostSharp.Aspects

Classes

AdviceArgs

In PostSharp, this object exposed the run-time execution context to the advice. However, in Metalama, advice do not execute at run time. Instead, advice are templates that generate run-time code. This run-time code does not need helper objects to represent the execution context.

Arguments

In Metalama, use meta.Target.Parameters.Values.

Aspect

The base aspect class in Metalama is Aspect.

AspectDescriptionAttribute

In Metalama, use DescriptionAttribute.

AspectInfo

This class was unused in PostSharp and has no equivalent in Metalama.

AspectInstance

In PostSharp, this class was used with IAspectProvider. In Metalama, no additional object is necessary when adding an aspect instance. Read-only access to aspect instances is provided through the IAspectInstance interface.

AspectSpecification

There is no equivalent to this class in Metalama.

AspectUtilities

There is no equivalent to this class in Metalama.

AssemblyLevelAspect

In Metalama, use CompilationAspect.

AsyncCallId

There is no equivalent to this type in Metalama. The equivalent concept can be built manually.

CompositionAspect

There is no composition aspect in Metalama, but you can build one by deriving the TypeAspect type, implementing the BuildAspect(IAspectBuilder<INamedType>) method, and calling builder.Advice.ImplementInterface(INamedType, INamedType, OverrideStrategy, Object). There is no concept of protected interface in Metalama.

CustomAttributeIntroductionAspect

There is no specific aspect class to add a custom attribute in Metalama, but only the advice factory method IntroduceAttribute(IDeclaration, IAttributeData, OverrideStrategy). Create an aspect class that calls this advice factory method from BuildAspect(IAspectBuilder<T>).

EventInterceptionArgs

In PostSharp, this object exposed the run-time execution context to an event interception advice. However, in Metalama, advice do not execute at run time. Instead, advice are templates that generate run-time code. This run-time code does not need helper objects to represent the execution context.

EventInterceptionAspect

In Metalama, use OverrideEventAspect. Overriding aspect invocation is not yet implemented in Metalama. There is currently no workaround.

EventLevelAspect

In Metalama, use EventAspect.

FieldLevelAspect

In Metalama, use FieldOrPropertyAspect.

FlowBehavior

There is no equivalent in Metalama because OnMethodBoundaryAspect is implemented with OverrideMethodAspect as a method template, therefore you have full control on the control flow.

InstanceLevelAspect

In Metalama, use TypeAspect. Note that aspects in Metalama have no run-time existence, so they cannot be instance-scoped. While porting a PostSharp InstanceLevelAspect into Metalama, you would typically introduce instance fields or properties into the target type, and use an initializer to initialize them.

LinesOfCodeAvoidedAttribute

This feature is not implemented in Metalama.

LocationBindingExtensions

LocationInitializationArgs

LocationInterceptionArgs

In PostSharp, this object exposed the run-time execution context to the advice. However, in Metalama, advice do not execute at run time. Instead, advice are templates that generate run-time code. This run-time code does not need helper objects to represent the execution context.

LocationInterceptionAspect

In Metalama, use OverrideFieldOrPropertyAspect.

LocationLevelAspect

In Metalama, use FieldOrPropertyAspect.

LocationValidationContext

Equivalent to ContractDirection.

ManagedResourceIntroductionAspect

Not implemented in Metalama.

MethodBindingInvokeAwaitable

No equivalent in Metalama. To override an async method, implement the OverrideMethodAspect.OverrideAsyncMethod() method and call meta.ProceedAsync().

MethodBindingInvokeAwaiter

No equivalent in Metalama. To override an async method, implement the OverrideMethodAspect.OverrideAsyncMethod() method and call meta.ProceedAsync().

MethodExecutionArgs

In PostSharp, this object exposed the run-time execution context to the advice. However, in Metalama, advice do not execute at run time. Instead, advice are templates that generate run-time code. This run-time code does not need helper objects to represent the execution context.

MethodImplementationAspect

In Metalama, use OverrideMethodAspect.

MethodInterceptionArgs

In PostSharp, this object exposed the run-time execution context to the advice. However, in Metalama, advice do not execute at run time. Instead, advice are templates that generate run-time code. This run-time code does not need helper objects to represent the execution context.

MethodInterceptionAspect

Use OverrideMethodAspect.

MethodInterceptionProceedAwaitable

No equivalent in Metalama. To override an async method, implement the OverrideMethodAspect.OverrideAsyncMethod() method and call meta.ProceedAsync().

MethodInterceptionProceedAwaiter

No equivalent in Metalama. To override an async method, implement the OverrideMethodAspect.OverrideAsyncMethod() method and call meta.ProceedAsync().

MethodLevelAspect

Equivalent to IAspect<T> where T is IMethod.

ModuleInitializerAttribute

Not supported in Metalama, but it is now supported by C# itself.

NullTaskSentinel

No equivalent in Metalama.

OnExceptionAspect

In Metalama, use OverrideMethodAspect and write your own try/catch block.

OnMethodBoundaryAspect

In Metalama, use OverrideMethodAspect.

SemanticallyAdvisedMethodKinds

TypeIdentity

TypeLevelAspect

UnsupportedTargetAction

There is no equivalent in Metalama because Metalama will throw an exception if the target is not supported.

Interfaces

IAspect

The base aspect interface is IAspect.

IAspectBuildSemantics

Aspects are purely build-time in Metalama, so all semantics are build semantics. The equivalent interface is therefore IAspect.

IAspectInstance

Use IAspectInstance.

IAspectProvider

In Metalama, you can add aspects using fabrics. In aspects, implement the BuildAspect(IAspectBuilder<T>). In fabrics, implement AmendType(ITypeAmender), AmendProject(IProjectAmender) or AmendNamespace(INamespaceAmender). In both cases, call the With<TMember>(Func<TTarget, IEnumerable<TMember>>) method, then call AddAspect<TAspect>().

IAspectRepositoryService

In Metalama, use extension methods of the code model.

IAssemblyLevelAspect

Equivalent to IAspect<T> where T is ICompilation.

IAssemblyLevelAspectBuildSemantics

Equivalent to IAspect<T> where T is ICompilation.

IAsyncMethodBinding

In PostSharp, a binding was a run-time object that allowed the run-time code of the aspect to call the target code. In Metalama, aspects no longer have run-time code. Instead, they have templates that are expanded at compile time and generate run-time code. Templates can generate run-time code that accesses target code using dynamic code or invokers. For methods, use meta.Target.Method.Invokers.

IAsyncMethodInterceptionAspect

In Metalama, use OverrideMethodAspect.

ICloneAwareAspect

There is no built-in support for cloning in Metalama at the moment.

ICompositionAspect

There is no composition aspect in Metalama, but you can build one by deriving the TypeAspect type, implementing the BuildAspect(IAspectBuilder<INamedType>) method, and calling builder.Advice.ImplementInterface(INamedType, INamedType, OverrideStrategy, Object). There is no concept of protected interface in Metalama.

ICustomAttributeIntroductionAspect

There is no specific aspect class to add a custom attribute in Metalama, but only the advice factory method IntroduceAttribute. Create an aspect class that calls this advice factory method from BuildAspect(IAspectBuilder<T>).

IEventBinding

In PostSharp, a binding was a run-time object that allowed the run-time code of the aspect to call the target code. In Metalama, aspects no longer have run-time code. Instead, they have templates that are expanded at compile time and generate run-time code. Templates can generate run-time code that accesses target code using dynamic code or invokers. For events, use meta.Target.Event.Invokers.

IEventInterceptionAspect

IEventLevelAspect

Equivalent to IAspect<T> where T is IEvent.

IEventLevelAspectBuildSemantics

Equivalent to IAspect<T> where T is IEvent.

IFieldLevelAspect

Equivalent to IAspect<T> where T is IField.

IFieldLevelAspectBuildSemantics

Equivalent to IAspect<T> where T is IField.

IInstanceScopedAspect

Not supported in Metalama because aspects no longer have a run-time existence. Instead, they only exist at compile time, and generate run-time code.

ILicensedAspect

No equivalent in Metalama.

ILocationBinding

In PostSharp, a binding was a run-time object that allowed the run-time code of the aspect to call the target code. In Metalama, aspects no longer have run-time code. Instead, they have templates that are expanded at compile time and generate run-time code. Templates can generate run-time code that accesses target code using dynamic code or invokers. For fields and properties, use meta.Target.FieldOrProperty.Invokers or IFieldOrProperty.ToExpression(IFieldOrProperty, IExpression).Value.

ILocationBinding<T>

In PostSharp, a binding was a run-time object that allowed the run-time code of the aspect to call the target code. In Metalama, aspects no longer have run-time code. Instead, they have templates that are expanded at compile time and generate run-time code. Templates can generate run-time code that accesses target code using dynamic code or invokers. For fields and properties, use meta.Target.FieldOrProperty.Invokers or IFieldOrProperty.ToExpression(IFieldOrProperty, IExpression).Value.

ILocationBindingAction<TPayload>

There is no equivalent in Metalama.

ILocationInterceptionArgs

In PostSharp, this interface exposed the run-time execution context to a location interception advice. However, in Metalama, advice do not execute at run time. Instead, advice are templates that generate run-time code. This run-time code does not need helper objects to represent the execution context.

ILocationInterceptionArgs<T>

In PostSharp, this interface exposed the run-time execution context to a location interception advice. However, in Metalama, advice do not execute at run time. Instead, advice are templates that generate run-time code. This run-time code does not need helper objects to represent the execution context.

ILocationInterceptionArgsAction<TPayload>

There is no equivalent in Metalama.

ILocationInterceptionAspect

In Metalama, use OverrideFieldOrPropertyAspect.

ILocationLevelAspect

Equivalent to IAspect<T> where T is IFieldOrProperty.

ILocationLevelAspectBuildSemantics

Equivalent to IAspect<T> where T is IFieldOrProperty.

ILocationValidationAspect

In Metalama, use ContractAspect.

ILocationValidationAspect<T>

In Metalama, use ContractAspect.

IManagedResourceIntroductionAspect

Not implemented in Metalama.

IMethodBinding

In PostSharp, a binding was a run-time object that allowed the run-time code of the aspect to call the target code. In Metalama, aspects no longer have run-time code. Instead, they have templates that are expanded at compile time and generate run-time code. Templates can generate run-time code that accesses target code using dynamic code or invokers. For methods, use meta.Target.Method.Invokers.

IMethodInterceptionAspect

In Metalama, use OverrideMethodAspect.

IMethodLevelAspect

Equivalent to IAspect<T> where T is IMethod.

IMethodLevelAspectBuildSemantics

Equivalent to IAspect<T> where T is IMethod.

IOnExceptionAspect

In Metalama, use OverrideMethodAspect and write your own try/catch block.

IOnInstanceLocationInitializedAspect

There is no equivalent of this aspect in Metalama because Metalama rewrites the code in such a way that field or property initializations go through the overridden setter. This is done by moving the initializers to the constructor, where it is safe to call the aspect.

IOnMethodBoundaryAspect

Use OverrideMethodAspect and implement your own try/catch/finally block.

IOnStateMachineBoundaryAspect

This feature is not implemented in Metalama and there is no workaround.

ITypeLevelAspect

Equivalent to IAspect<T> where T is INamedType.

ITypeLevelAspectBuildSemantics

Equivalent to IAspect<T> where T is INamedType.