Class UnionCaseMappingCollection
- Namespace
- Nerdbank.Json
- Assembly
- Nerdbank.Json.dll
An immutable collection of per-union identifier mappings that supplies C# union case identifiers.
public sealed class UnionCaseMappingCollection : IUnionTypeAliasProvider, IReadOnlyCollection<UnionCaseMapping>, IEnumerable<UnionCaseMapping>, IEnumerable
- Inheritance
-
UnionCaseMappingCollection
- Implements
- Inherited Members
Remarks
Each mapping is frozen when added to the collection, before the collection can be assigned to a serializer.
Constructors
UnionCaseMappingCollection(ReadOnlySpan<UnionCaseMapping>)
Initializes a new instance of the UnionCaseMappingCollection class and freezes its mappings.
public UnionCaseMappingCollection(ReadOnlySpan<UnionCaseMapping> mappings)
Parameters
mappingsReadOnlySpan<UnionCaseMapping>The mappings. Each union type may occur only once.
Exceptions
- ArgumentException
Multiple mappings target the same 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.
Methods
Create(ReadOnlySpan<UnionCaseMapping>)
Creates an immutable collection and freezes its mappings.
public static UnionCaseMappingCollection Create(ReadOnlySpan<UnionCaseMapping> mappings)
Parameters
mappingsReadOnlySpan<UnionCaseMapping>The mappings to include.
Returns
- UnionCaseMappingCollection
The immutable collection.
GetAlias(IUnionTypeShape, IUnionCaseShape)
Gets a custom identifier for a union case.
public DerivedTypeIdentifier? GetAlias(IUnionTypeShape unionShape, IUnionCaseShape caseShape)
Parameters
unionShapeIUnionTypeShapeThe shape of the containing union.
caseShapeIUnionCaseShapeA case belonging to
unionShape.
Returns
- DerivedTypeIdentifier?
The custom identifier, or null to use the normal identifier.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public ImmutableArray<UnionCaseMapping>.Enumerator GetEnumerator()
Returns
- ImmutableArray<UnionCaseMapping>.Enumerator
An enumerator that can be used to iterate through the collection.