Post­Sharp Documentation / API Reference / Post­Sharp.​Aspects.​Advices Namespace / Import­Member­Attribute Class

ImportMemberAttribute Class

Custom attribute that, when applied to an instance field of an aspect class, determines that this field should be bound to a method, event or property, of the target class of this aspect. Valid types for fields are a concrete Delegate (to bind to a method), Property<TValue> or Property<TValue, TIndex> (to bind to a property), or Event<TDelegate> (to bind to an event).
Inheritance Hierarchy
System.Object
  System.Attribute
    PostSharp.Aspects.Advices.Advice
      PostSharp.Aspects.Advices.ImportMemberAttribute

Namespace:  PostSharp.Aspects.Advices
Assembly:  PostSharp (in PostSharp.dll) Version: 5.0.38.0 (5.0.38.0)
Syntax
C#
public sealed class ImportMemberAttribute : Advice

The ImportMemberAttribute type exposes the following members.

Constructors
  NameDescription
Public methodImportMemberAttribute(String)
Initializes a new ImportMemberAttribute and specifies a single name for the member to import.
Public methodImportMemberAttribute(String[])
Initializes a new ImportMemberAttribute and specifies several possible names for the member to import.
Properties
  NameDescription
Public propertyDescription
A human-readable description of the current advice.
(Inherited from Advice.)
Public propertyIsRequired
Determines whether a build time error must be issued if the member to be imported is absent. If false, the binding field will be null in case the imported member is absent.
Public propertyLinesOfCodeAvoided
Reduction in the code lines count achieved by applying the advice instance to one code element.
(Inherited from Advice.)
Public propertyMemberNames
Array of possible names of imported member in the order of precedence.
Public propertyOrder
Determines when the member should be imported: either before (BeforeIntroductions) or after (AfterIntroductions) members have been introduced by the current aspect. Default is BeforeIntroductions.
Extension Methods
  NameDescription
Public Extension MethodQueryInterface<T>
Gets the implementation of a specified interface for the specified object.
(Defined by QueryInterfaceExtensions.)
Remarks

Fields annotated with the ImportMemberAttribute custom attribute must be public and must not be read only.

At runtime, these fields are assigned to a delegate (in case of method binding) or a pair of delegates (in case of event or property binding) allowing to invoke the imported member.

When IsRequired property is set to true and the target type does not contain a member of the required name and signature, then a build error will be raised.

When multiple member names are specified, the first existing member satisfying all conditions is used.

See Also