Open sandboxFocus

Method IntroduceField

IntroduceField(INamedType, string, IntroductionScope, OverrideStrategy, Action<IFieldBuilder>?, object?)

Introduces a field to the target type by specifying a template.

Declaration
IIntroductionAdviceResult<IField> IntroduceField(INamedType targetType, string template, IntroductionScope scope = IntroductionScope.Default, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IFieldBuilder>? buildField = null, object? tags = null)
Parameters
Type Name Description
INamedType targetType

The type into which the field must be introduced.

string template

Name of the introduced field.

IntroductionScope scope

Determines the scope (e.g. Instance or Static) of the introduced field. The default scope is Instance.

OverrideStrategy whenExists

Determines the implementation strategy when a field of the same name is already declared in the target type. The default strategy is to fail with a compile-time error.

Action<IFieldBuilder> buildField

An optional callback that allows you to configure the introduced field, such as changing its name, type, accessibility, or adding custom attributes.

object tags

An optional opaque object of anonymous type passed to the template and exposed under the Tags property of the meta API.

Returns
Type Description
IIntroductionAdviceResult<IField>

An IIntroductionAdviceResult<T> representing the result of the advice. The Declaration property provides access to the introduced field.

See Also

IntroduceField(INamedType, string, IType, IntroductionScope, OverrideStrategy, Action<IFieldBuilder>?, object?)

Introduces a field to the target type by specifying a field name and IType.

Declaration
IIntroductionAdviceResult<IField> IntroduceField(INamedType targetType, string fieldName, IType fieldType, IntroductionScope scope = IntroductionScope.Default, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IFieldBuilder>? buildField = null, object? tags = null)
Parameters
Type Name Description
INamedType targetType

The type into which the field must be introduced.

string fieldName

Name of the introduced field.

IType fieldType

Type of the introduced field.

IntroductionScope scope

Determines the scope (e.g. Instance or Static) of the introduced field. The default scope is Instance.

OverrideStrategy whenExists

Determines the implementation strategy when a field of the same name is already declared in the target type. The default strategy is to fail with a compile-time error.

Action<IFieldBuilder> buildField

An optional callback that allows you to configure the introduced field, such as changing its accessibility or adding custom attributes.

object tags

An optional opaque object of anonymous type passed to the template and exposed under the Tags property of the meta API.

Returns
Type Description
IIntroductionAdviceResult<IField>

An IIntroductionAdviceResult<T> representing the result of the advice. The Declaration property provides access to the introduced field.

See Also

IntroduceField(INamedType, string, Type, IntroductionScope, OverrideStrategy, Action<IFieldBuilder>?, object?)

Introduces a field to the target type by specifying a field name and Type.

Declaration
IIntroductionAdviceResult<IField> IntroduceField(INamedType targetType, string fieldName, Type fieldType, IntroductionScope scope = IntroductionScope.Default, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IFieldBuilder>? buildField = null, object? tags = null)
Parameters
Type Name Description
INamedType targetType

The type into which the field must be introduced.

string fieldName

Name of the introduced field.

Type fieldType

Type of the introduced field.

IntroductionScope scope

Determines the scope (e.g. Instance or Static) of the introduced field. The default scope is Instance.

OverrideStrategy whenExists

Determines the implementation strategy when a field of the same name is already declared in the target type. The default strategy is to fail with a compile-time error.

Action<IFieldBuilder> buildField

An optional callback that allows you to configure the introduced field, such as changing its accessibility or adding custom attributes.

object tags

An optional opaque object of anonymous type passed to the template and exposed under the Tags property of the meta API.

Returns
Type Description
IIntroductionAdviceResult<IField>

An IIntroductionAdviceResult<T> representing the result of the advice. The Declaration property provides access to the introduced field.

See Also