Class DerivedTypeDuckTyping
- Namespace
- Nerdbank.MessagePack
- Assembly
- Nerdbank.MessagePack.dll
A shape-based union that can distinguish between union cases based on their structural characteristics rather than explicit aliases.
public class DerivedTypeDuckTyping : DerivedTypeUnion
- Inheritance
-
DerivedTypeDuckTyping
- Inherited Members
Remarks
This union strategy analyzes the provided type shapes to identify distinguishing characteristics such as:
- Required properties that appear only in specific union cases
The resulting converter does not use explicit type aliases and instead inspects the MessagePack structure during deserialization to determine the appropriate union case to deserialize into.
Note that this approach may be slower than alias-based unions as it may require buffering the entire value for analysis.
Constructors
DerivedTypeDuckTyping(ITypeShape, params ReadOnlySpan<ITypeShape>)
Initializes a new instance of the DerivedTypeDuckTyping class.
public DerivedTypeDuckTyping(ITypeShape baseShape, params ReadOnlySpan<ITypeShape> derivedTypeShapes)
Parameters
baseShape
ITypeShapeThe shape of the base type.
derivedTypeShapes
ReadOnlySpan<ITypeShape>The shapes of the derived types.
Properties
BaseType
Gets the base union type.
public override Type BaseType { get; }