Open sandboxFocus

Class IntroduceInterfaceAttribute

Custom attribute that, when applied to an aspect class, specifies that the aspect should introduce a given interface into the type to which the aspect is applied.

Inheritance
IntroduceInterfaceAttribute
Namespace: PostSharp.Aspects.Advices
Assembly: PostSharp.dll
Syntax
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public sealed class IntroduceInterfaceAttribute : Advice
Remarks

The introduced interface will be implemented explicitly by the type to which the aspect is applied.

The aspect class must itself implement the interface: the target type delegates the implementation to the aspect instance, so the aspect is typically derived from InstanceLevelAspect. Because the interface is added after compilation, the C# compiler does not know that the target type implements it; in the same project, use Cast<TSource, TTarget>(TSource) to convert an instance of the target type to the interface with a build-time check.

To introduce individual methods, properties or events instead of a whole interface, use IntroduceMemberAttribute.

Constructors

Name Description
IntroduceInterfaceAttribute(Type)

Initializes a new instance of the IntroduceInterfaceAttribute class.

Properties

Name Description
AncestorOverrideAction

Gets or sets the action (Fail or Ignore) to take when an ancestor of the interface specified in the constructor of this custom attribute is already implemented by the type to which the current aspect is applied.

OverrideAction

Gets or sets the action (Fail or Ignore) to take when the interface specified in the constructor of this custom attribute is already implemented by the type to which the current aspect is applied.

See Also