Open sandboxFocus

Method IntroduceAutomaticProperty

IntroduceAutomaticProperty(IAdviser<INamedType>, string, Type, IntroductionScope, OverrideStrategy, Action<IPropertyBuilder>?, object?)

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

Declaration
public static IIntroductionAdviceResult<IProperty> IntroduceAutomaticProperty(this IAdviser<INamedType> adviser, string propertyName, Type propertyType, IntroductionScope scope = IntroductionScope.Default, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IPropertyBuilder>? buildProperty = null, object? tags = null)
Parameters
Type Name Description
IAdviser<INamedType> adviser

An adviser for a named type.

string propertyName

Name of the introduced field.

Type propertyType

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<IPropertyBuilder> buildProperty
object tags
Returns
Type Description
IIntroductionAdviceResult<IProperty>

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

See Also

IntroduceAutomaticProperty(IAdviser<INamedType>, string, IType, IntroductionScope, OverrideStrategy, Action<IPropertyBuilder>?, object?)

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

Declaration
public static IIntroductionAdviceResult<IProperty> IntroduceAutomaticProperty(this IAdviser<INamedType> adviser, string propertyName, IType propertyType, IntroductionScope scope = IntroductionScope.Default, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IPropertyBuilder>? buildProperty = null, object? tags = null)
Parameters
Type Name Description
IAdviser<INamedType> adviser

An adviser for a named type.

string propertyName

Name of the introduced field.

IType propertyType

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<IPropertyBuilder> buildProperty
object tags
Returns
Type Description
IIntroductionAdviceResult<IProperty>

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

See Also