Table of Contents

Struct ConverterContext<TEncoder, TDecoder>

Namespace
ShapeShift
Assembly
ShapeShift.dll

Context in which a IShapeShiftConverterFactory<TEncoder, TDecoder> is invoked.

public struct ConverterContext<TEncoder, TDecoder> where TEncoder : IEncoder, allows ref struct where TDecoder : IDecoder, allows ref struct

Type Parameters

TEncoder

The type of encoder to use.

TDecoder

The type of decoder to use.

Inherited Members

Remarks

Provides access to other converters that may be required by the requested converter.

Properties

DeserializeDefaultValues

Gets the policy that controls missing and null values during deserialization.

public DeserializeDefaultValuesPolicy DeserializeDefaultValues { get; }

Property Value

DeserializeDefaultValuesPolicy

Remarks

A converter that validates required or non-nullable members itself should honor this policy so that its strictness matches the serializer's built-in converters.

PropertyNamingPolicy

Gets the transformation function to apply to property names before serializing them.

public ShapeShiftNamingPolicy? PropertyNamingPolicy { get; }

Property Value

ShapeShiftNamingPolicy

The default value is null, indicating that property names should be persisted exactly as they are declared in .NET.

SerializeDefaultValues

Gets the policy that controls whether properties with default values are serialized.

public SerializeDefaultValuesPolicy SerializeDefaultValues { get; }

Property Value

SerializeDefaultValuesPolicy

Remarks

A converter that decides for itself whether to write a member should honor this policy so that its output matches what the serializer's built-in converters would produce for the same configuration.

TypeShapeProvider

Gets the PolyType.ITypeShapeProvider that can provide shapes for given types.

public readonly ITypeShapeProvider TypeShapeProvider { get; }

Property Value

ITypeShapeProvider

Methods

GetConverter(ITypeShape)

Gets a converter for a given type shape.

public ShapeShiftConverter<TEncoder, TDecoder> GetConverter(ITypeShape typeShape)

Parameters

typeShape ITypeShape

The shape of the type to be converted.

Returns

ShapeShiftConverter<TEncoder, TDecoder>

The converter.

Remarks

This method is intended only for use by custom converters in order to delegate conversion of sub-values.

Exceptions

InvalidOperationException

Thrown if no serialization operation is in progress.

GetConverter(Type, ITypeShapeProvider?)

Gets a converter for a given type shape.

public ShapeShiftConverter<TEncoder, TDecoder> GetConverter(Type type, ITypeShapeProvider? provider = null)

Parameters

type Type

The type to be converted.

provider ITypeShapeProvider
The shape provider for the type(s) to be serialized. This might be PolyType.ReflectionProvider.ReflectionTypeShapeProvider.Default to use reflection-based shapes. It might also be the value of the GeneratedTypeShapeProvider static property on a witness class (a class on which PolyType.GenerateShapeForAttribute<T> has been applied), although for source generated shapes, overloads that do not take an PolyType.ITypeShapeProvider offer better performance. It can also come from TypeShapeProvider. A null value will be filled in with TypeShapeProvider.

Returns

ShapeShiftConverter<TEncoder, TDecoder>

The converter.

Remarks

This method is intended only for use by custom converters in order to delegate conversion of sub-values.

Exceptions

InvalidOperationException

Thrown if no serialization operation is in progress.

GetConverter<T>()

Gets a converter for some type.

public ShapeShiftConverter<T, TEncoder, TDecoder> GetConverter<T>() where T : IShapeable<T>

Returns

ShapeShiftConverter<T, TEncoder, TDecoder>

The converter.

Type Parameters

T

The type for which a converter is required.

GetConverter<T>(ITypeShapeProvider?)

Gets a converter for a specific type.

public ShapeShiftConverter<T, TEncoder, TDecoder> GetConverter<T>(ITypeShapeProvider? provider)

Parameters

provider ITypeShapeProvider
The shape provider for the type(s) to be serialized. This might be PolyType.ReflectionProvider.ReflectionTypeShapeProvider.Default to use reflection-based shapes. It might also be the value of the GeneratedTypeShapeProvider static property on a witness class (a class on which PolyType.GenerateShapeForAttribute<T> has been applied), although for source generated shapes, overloads that do not take an PolyType.ITypeShapeProvider offer better performance. It can also come from TypeShapeProvider. A null value will be filled in with TypeShapeProvider.

Returns

ShapeShiftConverter<T, TEncoder, TDecoder>

The converter.

Type Parameters

T

The type to be converted.

Remarks

This method is intended only for use by custom converters in order to delegate conversion of sub-values.

Exceptions

InvalidOperationException

Thrown if no serialization operation is in progress.

GetConverter<T>(ITypeShape<T>)

Gets a converter for a given type shape.

public ShapeShiftConverter<T, TEncoder, TDecoder> GetConverter<T>(ITypeShape<T> typeShape)

Parameters

typeShape ITypeShape<T>

The shape of the type to be converted.

Returns

ShapeShiftConverter<T, TEncoder, TDecoder>

The converter.

Type Parameters

T

The type to be converted.

Remarks

This method is intended only for use by custom converters in order to delegate conversion of sub-values.

Exceptions

InvalidOperationException

Thrown if no serialization operation is in progress.

GetConverter<T, TProvider>()

Gets a converter for some type.

public ShapeShiftConverter<T, TEncoder, TDecoder> GetConverter<T, TProvider>() where TProvider : IShapeable<T>

Returns

ShapeShiftConverter<T, TEncoder, TDecoder>

The converter.

Type Parameters

T

The type for which a converter is required.

TProvider

The provider of the type's shape.