Open sandboxFocus

Method IntroduceRecord

IntroduceRecord(IAdviser<INamespaceOrNamedType>, string, RecordKind, OverrideStrategy, Action<IRecordBuilder>?)

Introduces a new record into the current namespace (as a top-level type) or type (as a nested type). Use the With<TNewDeclaration>(TNewDeclaration) or WithNamespace(IAdviser<ICompilation>, string) method to introduce the record to a different type or namespace than the current one.

Declaration
public static IIntroductionAdviceResult<INamedType> IntroduceRecord(this IAdviser<INamespaceOrNamedType> adviser, string name, RecordKind recordKind = RecordKind.Class, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IRecordBuilder>? buildRecord = null)
Parameters
Type Name Description
IAdviser<INamespaceOrNamedType> adviser

An adviser for a named type or namespace.

string name

The record name.

RecordKind recordKind

Whether the record is a record class or a record struct. The default is a record class.

OverrideStrategy whenExists

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

Action<IRecordBuilder> buildRecord

An optional delegate that modifies the IRecordBuilder that represents the introduced record.

Returns
Type Description
IIntroductionAdviceResult<INamedType>

An IIntroductionAdviceResult<T> that exposes the outcome of the operation and the introduced INamedType.

See Also