Open sandboxFocus

Method IntroduceClass

IntroduceClass(IAdviser<INamespaceOrNamedType>, string, OverrideStrategy, Action<INamedTypeBuilder>?)

Introduces a new class 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 class to a different type or namespace than the current one.

Declaration
public static IIntroductionAdviceResult<INamedType> IntroduceClass(this IAdviser<INamespaceOrNamedType> adviser, string name, OverrideStrategy whenExists = OverrideStrategy.Default, Action<INamedTypeBuilder>? buildType = null)
Parameters
Type Name Description
IAdviser<INamespaceOrNamedType> adviser

An adviser for a named type or namespace.

string name

The class name.

OverrideStrategy whenExists

Determines the implementation strategy when a class 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<INamedTypeBuilder> buildType

An optional delegate that modifies the INamedTypeBuilder that represents the introduced class.

Returns
Type Description
IIntroductionAdviceResult<INamedType>

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

See Also