Table of Contents

Interface IUnionCaseShape

Namespace
PolyType.Abstractions
Assembly
PolyType.dll

Provides a shape model for a union case.

public interface IUnionCaseShape

Properties

Index

Gets the unique index corresponding to the current union case.

int Index { get; }

Property Value

int

Remarks

Corresponds to the index of this instance in the parent UnionCases list. While similar to Tag, the value of the index is distinct and is not part of the data contract.

IsNullable

Gets a value indicating whether this case admits a null payload.

bool IsNullable { get; }

Property Value

bool

Remarks

For C# unions, this reflects the nullable contract of the case's creation parameter. Always returns false for F# unions and type hierarchies. A case's use of a null CLR representation does not make its payload nullable.

IsTagSpecified

Gets a value indicating whether Tag has been explicitly specified or inferred in a less stable way.

bool IsTagSpecified { get; }

Property Value

bool

Name

Gets the unique string identifier for the current union case.

string Name { get; }

Property Value

string

Remarks

The value is usually the name of the derived type but can be overridden via the Name property.

Tag

Gets the unique integer identifier for the current union case.

int Tag { get; }

Property Value

int

Remarks

The value typically corresponds to the order of DerivedTypeShapeAttribute declarations but can be overridden via the Tag property.

UnionCaseType

Gets the underlying type shape of the union case.

ITypeShape UnionCaseType { get; }

Property Value

ITypeShape

Remarks

F# case bodies and explicitly registered hierarchy base cases are contextual views. C# payload shapes and proper-derived hierarchy case shapes are non-contextual.

Methods

Accept(TypeShapeVisitor, object?)

Accepts an TypeShapeVisitor for strongly-typed traversal.

object? Accept(TypeShapeVisitor visitor, object? state = null)

Parameters

visitor TypeShapeVisitor

The visitor to accept.

state object

The state parameter to pass to the underlying visitor.

Returns

object

The object result returned by the visitor.