Open sandboxFocus

Method IntroduceField

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

Introduces a field to the target type by specifying a template. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another declaration than the current one.

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

An adviser for a named type.

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 property 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
object tags
Returns
Type Description
IIntroductionAdviceResult<IField>

An IPropertyBuilder that allows to dynamically change the name or type of the introduced property.

See Also

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

Introduces a field to the target type by specifying a field name and IType. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another declaration than the current one.

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

An adviser for a named type.

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 property 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
object tags
Returns
Type Description
IIntroductionAdviceResult<IField>

An IPropertyBuilder that allows to dynamically change the name or type of the introduced property.

See Also

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

Introduces a field to the target type by specifying a field name and Type. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another declaration than the current one.

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

An adviser for a named type.

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 property 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
object tags
Returns
Type Description
IIntroductionAdviceResult<IField>

An IPropertyBuilder that allows to dynamically change the name or type of the introduced property.

See Also