Table of Contents

Interface IUnionTypeShape<TUnion>

Namespace
PolyType.Abstractions
Assembly
PolyType.dll

Provides a strongly typed discriminated union shape model for a .NET type.

public interface IUnionTypeShape<TUnion> : ITypeShape<TUnion>, IUnionTypeShape, ITypeShape

Type Parameters

TUnion

The type of the union.

Inherited Members

Remarks

Supports type hierarchies configured using DerivedTypeShapeAttribute or InferClosedTypePolymorphism, F# discriminated unions, and types implementing the C# union member pattern.

Properties

BaseType

Gets the underlying type shape of the union base type.

ITypeShape<TUnion> BaseType { get; }

Property Value

ITypeShape<TUnion>

Remarks

Type hierarchies use this shape as a fallback for values not matching a registered case. F# and C# unions expose an empty object shape without a constructor.

Methods

GetGetUnionCaseIndex()

Creates a delegate that computes the union case index for a given value.

Getter<TUnion, int> GetGetUnionCaseIndex()

Returns

Getter<TUnion, int>

A delegate that computes the union case index for a given value.

Remarks

The delegate returns an index pointing to the UnionCases list. It should be noted that the value of the index is distinct from the Tag property. An index of -1 indicates that no union case was selected. C# unions select the first nullable case for null values. For a C# union payload that matches no case, including null when no case admits it, the delegate throws InvalidOperationException as for a non-exhaustive switch instead of returning -1.