Aspect that, when applied on a type, introduces one or many new interfaces into that type.
Implements
Namespace: PostSharp.Aspects
Assembly: PostSharp.dll
Syntax
[AttributeUsage(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]
[MulticastAttributeUsage(MulticastTargets.Class|MulticastTargets.Struct, AllowMultiple = true)]
[AspectConfigurationAttributeType(typeof(CompositionAspectConfigurationAttribute))]
[Serializer(null)]
public abstract class CompositionAspect : TypeLevelAspect, ITypeLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, ICompositionAspect, ITypeLevelAspect, IAspectRemarks
<div class="NOTE"><h5>note</h5><p>
Consider using a composite aspect and introducing an interface using <xref href="PostSharp.Aspects.Advices.IntroduceMemberAttribute" data-throw-if-not-resolved="false"></xref>
instead of using a <xref href="PostSharp.Aspects.CompositionAspect" data-throw-if-not-resolved="false"></xref>.
</p></div>
<p>
The <xref href="PostSharp.Aspects.CompositionAspect.GetPublicInterfaces(System.Type)" data-throw-if-not-resolved="false"></xref> method
is invoked at build time. At runtime, the method <xref href="PostSharp.Aspects.CompositionAspect.CreateImplementationObject(PostSharp.Aspects.AdviceArgs)" data-throw-if-not-resolved="false"></xref>
should return an object implementing all interfaces.
</p>
<p>
Use the <xref href="PostSharp.Post" data-throw-if-not-resolved="false"></xref>.<xref href="PostSharp.Post.Cast%60%602(%60%600)" data-throw-if-not-resolved="false"></xref>
method to cast the enhanced type to the newly implemented interface. This
cast is verified during post-compilation.
</p>
<p>
Properties <xref href="PostSharp.Aspects.CompositionAspect.OverrideAction" data-throw-if-not-resolved="false"></xref> and <xref href="PostSharp.Aspects.CompositionAspect.AncestorOverrideAction" data-throw-if-not-resolved="false"></xref> determine
what should happen if the target type already implements the interface directly or indirectly.
</p>
<p>
By default, the object implementing the interface is stored as a serializable field. If the property
<xref href="PostSharp.Aspects.CompositionAspect.NonSerializedImplementation" data-throw-if-not-resolved="false"></xref> is set to <code>true</code>, this field will be marked
as <xref href="System.NonSerializedAttribute" data-throw-if-not-resolved="false"></xref>.
</p>
<br />
<p>
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 PostSharp is used on a platform that does not support aspect serialization (such as .NET Compact Framework, Silverlight, or Windows Phone), or when another aspect serializer is used, it is not necessary to mark the aspect class as serializable. For more information, see Understanding Aspect Serialization .
Constructors
| Name | Description |
|---|---|
| CompositionAspect() |
Properties
| Name | Description |
|---|---|
| AncestorOverrideAction | Specifies the action (Fail or Ignore) to be overtaken when an ancestor of one of the interfaces returned by GetPublicInterfaces(Type) is already implemented by the type to which the current aspect is applied. |
| GenerateImplementationAccessor | This property has no effect. |
| NonSerializedImplementation | Determines whether the field containing the interface implementation (and storing the object returned by CreateImplementationObject(AdviceArgs)) should be excluded from serialization by BinaryFormatter. The same effect is typically obtained by applying the NonSerializedAttribute custom attribute to the field. |
| OverrideAction | Specifies the action (Fail or Ignore) to be overtaken when one of the interfaces returned by the GetPublicInterfaces(Type) method is already implemented by the type to which the current aspect is applied. |
Methods
| Name | Description |
|---|---|
| CreateAspectConfiguration() | Method invoked at build time to create a concrete AspectConfiguration instance specifically for the current Aspect type. |
| CreateImplementationObject(AdviceArgs) | Method invoked at runtime, during the initialization of instances of the target type, to create the composed object. |
| GetPublicInterfaces(Type) | Gets the array of interfaces that should be introduced publicly into the target type 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. |