Class Codecs
Creates codecs and composes the supported value shapes.
public static class Codecs
- Inheritance
-
Codecs
- Inherited Members
Remarks
These helpers build complete endpoints directly and do not retain a runtime field graph.
Properties
Boolean
public static Codec<bool> Boolean { get; }
Property Value
Double
public static Codec<double> Double { get; }
Property Value
Int32
public static Codec<int> Int32 { get; }
Property Value
Int64
public static Codec<long> Int64 { get; }
Property Value
NamedNonFiniteSingle
public static Codec<float> NamedNonFiniteSingle { get; }
Property Value
Single
public static Codec<float> Single { get; }
Property Value
String
public static Codec<string> String { get; }
Property Value
Methods
Array<T>(Codec<T>)
Builds an array codec and validates each element at its index path.
public static Codec<T[]> Array<T>(Codec<T> element)
Parameters
elementCodec<T>
Returns
- Codec<T[]>
Type Parameters
T
Create<T>(JsonRead<T>, BsonRead<T>, BsonWrite<T>, BsonRootKind, CodecValidate<T>)
Creates a codec from direct JSON decoding, BSON, and validation programs.
public static Codec<T> Create<T>(JsonRead<T> decodeJson, BsonRead<T> decodeBson, BsonWrite<T> encodeBson, BsonRootKind bsonRootKind, CodecValidate<T> validate)
Parameters
decodeJsonJsonRead<T>decodeBsonBsonRead<T>encodeBsonBsonWrite<T>bsonRootKindBsonRootKindvalidateCodecValidate<T>
Returns
- Codec<T>
Type Parameters
T
Enum<T>(IReadOnlyDictionary<T, string>)
Builds an enum codec from one fixed map of enum values to encoded names.
public static Codec<T> Enum<T>(IReadOnlyDictionary<T, string> names) where T : struct, Enum
Parameters
namesIReadOnlyDictionary<T, string>
Returns
- Codec<T>
Type Parameters
T
List<T>(Codec<T>)
Builds a list codec and validates each element at its index path.
public static Codec<List<T>> List<T>(Codec<T> element)
Parameters
elementCodec<T>
Returns
Type Parameters
T
NullableReference<T>(Codec<T>)
Allows a reference value to be null in both formats while reusing its validator when present.
public static Codec<T?> NullableReference<T>(Codec<T> element) where T : class
Parameters
elementCodec<T>
Returns
- Codec<T>
Type Parameters
T
NullableValue<T>(Codec<T>)
Allows a value type to be null in both formats while reusing its validator when present.
public static Codec<T?> NullableValue<T>(Codec<T> element) where T : struct
Parameters
elementCodec<T>
Returns
- Codec<T?>
Type Parameters
T
OrdinalDictionary<T>(Codec<T>)
Builds a map codec whose string keys use ordinal comparison.
public static Codec<Dictionary<string, T>> OrdinalDictionary<T>(Codec<T> element)
Parameters
elementCodec<T>
Returns
- Codec<Dictionary<string, T>>
Type Parameters
T
TryTransform<TSource, TResult>(Codec<TSource>, CodecTryTransform<TSource, TResult>, CodecTryTransform<TResult, TSource>, string)
Reuses another codec through explicit forward and reverse conversions.
public static Codec<TResult> TryTransform<TSource, TResult>(Codec<TSource> representation, CodecTryTransform<TSource, TResult> forward, CodecTryTransform<TResult, TSource> reverse, string failureMessage)
Parameters
representationCodec<TSource>forwardCodecTryTransform<TSource, TResult>reverseCodecTryTransform<TResult, TSource>failureMessagestring
Returns
- Codec<TResult>
Type Parameters
TSourceTResult