Table of Contents

Class UnionCaseMapping

Namespace
Nerdbank.Json
Assembly
Nerdbank.Json.dll

A mapping of C# union payload types to custom identifiers.

public sealed class UnionCaseMapping : IReadOnlyCollection<KeyValuePair<Type, DerivedTypeIdentifier>>, IEnumerable<KeyValuePair<Type, DerivedTypeIdentifier>>, IEnumerable
Inheritance
UnionCaseMapping
Implements
Inherited Members

Remarks

No type shape provider is needed. The union shape supplies the payload shapes and conversions. Types not registered in this mapping retain their normal identifiers. Adding a mapping to a collection freezes it, preventing further mutation.

Constructors

UnionCaseMapping(Type)

Initializes a new instance of the UnionCaseMapping class.

public UnionCaseMapping(Type unionType)

Parameters

unionType Type

The containing C# union type.

Properties

Count

Gets the number of elements in the collection.

public int Count { get; }

Property Value

int

The number of elements in the collection.

UnionType

Gets the containing union type.

public Type UnionType { get; }

Property Value

Type

Methods

Add(DerivedTypeIdentifier, Type)

Adds a payload type and its identifier.

public void Add(DerivedTypeIdentifier alias, Type caseType)

Parameters

alias DerivedTypeIdentifier

The identifier for the payload type.

caseType Type

The payload type. Membership in the union is checked when its converter is constructed.

Exceptions

ArgumentException

The identifier is uninitialized, or the type or identifier is already registered.

InvalidOperationException

The mapping has been frozen.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<KeyValuePair<Type, DerivedTypeIdentifier>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<Type, DerivedTypeIdentifier>>

An enumerator that can be used to iterate through the collection.