Represents a request for a field to exist in or to be introduced into the target type of the aspect. The field is introduced into the target type, or the introduction is skipped when the target type already has a compatible field, as specified by WhenCompatibleFieldExists and WhenIncompatibleMemberExists.
Namespace: PostSharp.Aspects.Advices
Assembly: PostSharp.dll
Syntax
public sealed class IntroduceFieldAdviceInstance : AdviceInstanceRemarks
An aspect returns an IntroduceFieldAdviceInstance from ProvideAdvices(object), so that the type, the name and the number of the fields can depend on the target. The target type is the type to which the aspect is applied, or the declaring type of the member to which it is applied. Any aspect can request fields, including a statically scoped aspect, which then keeps per-object state in the target object.
The advices of the aspect instance that made the request receive the field through an advice parameter annotated with ImportMemberAttribute. With a Name, the parameter imports the field by this name, whatever the real name of the field, and the requested name wins over a member of the target type that has the same name. Without a name, the parameter imports the field by its type, and the fields requested by the aspect instance win over the other members of the target type. The requested name is visible only to the aspect instance that made the request.
The request does not initialize the field: a new field has the default value of its type when the object is created.
When several aspects request a field that can resolve to the same field, they must be ordered by aspect dependencies, because the result depends on the order: the request declares the effect MemberIntroduction, and the effect returned by GetMemberIntroductionEffect(string) for its name, or for its type when it has no name. Equivalent requests that use an existing field, such as the requests of one aspect applied to several members, share the field whatever their order and need no dependency.
Constructors
| Name | Description |
|---|---|
| IntroduceFieldAdviceInstance(Type) | Initializes a new instance of the IntroduceFieldAdviceInstance class. |
Properties
| Name | Description |
|---|---|
| CustomAttributes | Gets the custom attributes added to the introduced field, as ObjectConstruction objects. They are not added to an existing field to which the request resolves. |
| FieldType | Gets the type of the field. |
| IsReadOnly | Gets or sets a value indicating whether the introduced field is read-only ( |
| IsSerialized | Gets or sets a value indicating whether the field is serialized with the object. The default value is |
| IsStatic | Gets or sets a value indicating whether the field is static. A static field of a generic type exists once per closed generic type. |
| MasterAspectMember | Gets the main field or method of the aspect class that the current AdviceInstance relates to. |
| Name | Gets or sets the requested name of the field, or |
| Visibility | Gets or sets the visibility of the introduced field. The default value is Private. |
| WhenCompatibleFieldExists | Gets or sets the action taken when the target type already has a field that is compatible with the request: the field that has the requested name, or, without a name, a field of the type of the request. The default value is Fail. |
| WhenIncompatibleMemberExists | Gets or sets the action taken when a member of the target type has the requested name but is not a compatible field. It applies only to a request with a Name. The default value is Fail. |