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.
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 property. |
| Type | propertyType | Type of the introduced property. |
| IntroductionScope | scope | Determines the scope (e.g. Instance or Static) of the introduced property. 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 | An optional delegate that modifies the IPropertyBuilder representing the introduced property. |
| object | tags | An optional object (typically of anonymous type) passed to the template and accessible via |
Returns
| Type | Description |
|---|---|
| IIntroductionAdviceResult<IProperty> | An IIntroductionAdviceResult<T> exposing the introduced IProperty. |
Remarks
This method introduces a simple auto-implemented property (similar to public string Name { get; set; })
without requiring a template. The property will have both a getter and setter with automatic backing field management.
Use buildProperty to customize accessibility or other characteristics.
Use With<TNewDeclaration>(TNewDeclaration) to introduce the property into a different type than the current target.
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.
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 property. |
| IType | propertyType | Type of the introduced property. |
| IntroductionScope | scope | Determines the scope (e.g. Instance or Static) of the introduced property. 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 | An optional delegate that modifies the IPropertyBuilder representing the introduced property. |
| object | tags | An optional object (typically of anonymous type) passed to the template and accessible via |
Returns
| Type | Description |
|---|---|
| IIntroductionAdviceResult<IProperty> | An IIntroductionAdviceResult<T> exposing the introduced IProperty. |
Remarks
This overload is identical to the Type-based overload, but accepts an IType parameter for working with Metalama's code model types. The property will be auto-implemented with both getter and setter.
Use With<TNewDeclaration>(TNewDeclaration) to introduce the property into a different type than the current target.