Open sandboxFocus

Method IntroduceUnion

IntroduceUnion(IAdviser<INamespaceOrNamedType>, string, Action<IUnionBuilder>, OverrideStrategy)

Introduces a new union, written with the union keyword, 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 union to a different type or namespace than the current one.

Declaration
public static IIntroductionAdviceResult<INamedType> IntroduceUnion(this IAdviser<INamespaceOrNamedType> adviser, string name, Action<IUnionBuilder> buildUnion, OverrideStrategy whenExists = OverrideStrategy.Default)
Parameters
Type Name Description
IAdviser<INamespaceOrNamedType> adviser

An adviser for a named type or namespace.

string name

The union name.

Action<IUnionBuilder> buildUnion

A callback that configures the introduced union. It must add at least one case, because the language requires a union to have one, which is why this parameter is required and precedes whenExists.

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.

Returns
Type Description
IIntroductionAdviceResult<INamedType>

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

See Also