Class SliceDecoderExtensions
Provides extension methods for SliceDecoder to decode sequences or dictionaries.
public static class SliceDecoderExtensions
- Inheritance
-
SliceDecoderExtensions
- Inherited Members
Methods
DecodeDictionaryWithOptionalValueType<TDictionary, TKey, TValue>(ref SliceDecoder, Func<int, TDictionary>, DecodeFunc<TKey>, DecodeFunc<TValue?>)
Decodes a dictionary with an optional value type (T? in Slice).
public static TDictionary DecodeDictionaryWithOptionalValueType<TDictionary, TKey, TValue>(this ref SliceDecoder decoder, Func<int, TDictionary> dictionaryFactory, DecodeFunc<TKey> keyDecodeFunc, DecodeFunc<TValue?> valueDecodeFunc) where TDictionary : ICollection<KeyValuePair<TKey, TValue?>> where TKey : notnull
Parameters
decoder
SliceDecoderThe Slice decoder.
dictionaryFactory
Func<int, TDictionary>The factory for creating the dictionary instance.
keyDecodeFunc
DecodeFunc<TKey>The decode function for each key of the dictionary.
valueDecodeFunc
DecodeFunc<TValue>The decode function for each non-null value of the dictionary.
Returns
- TDictionary
The dictionary decoded by this decoder.
Type Parameters
TDictionary
The type of the returned dictionary.
TKey
The type of the keys in the dictionary.
TValue
The type of the values in the dictionary.
DecodeDictionary<TDictionary, TKey, TValue>(ref SliceDecoder, Func<int, TDictionary>, DecodeFunc<TKey>, DecodeFunc<TValue>)
Decodes a dictionary.
public static TDictionary DecodeDictionary<TDictionary, TKey, TValue>(this ref SliceDecoder decoder, Func<int, TDictionary> dictionaryFactory, DecodeFunc<TKey> keyDecodeFunc, DecodeFunc<TValue> valueDecodeFunc) where TDictionary : ICollection<KeyValuePair<TKey, TValue>> where TKey : notnull
Parameters
decoder
SliceDecoderThe Slice decoder.
dictionaryFactory
Func<int, TDictionary>The factory for creating the dictionary instance.
keyDecodeFunc
DecodeFunc<TKey>The decode function for each key of the dictionary.
valueDecodeFunc
DecodeFunc<TValue>The decode function for each value of the dictionary.
Returns
- TDictionary
The dictionary decoded by this decoder.
Type Parameters
TDictionary
The type of the returned dictionary.
TKey
The type of the keys in the dictionary.
TValue
The type of the values in the dictionary.
DecodeResult<TSuccess, TFailure>(ref SliceDecoder, DecodeFunc<TSuccess>, DecodeFunc<TFailure>)
Decodes a result.
public static Result<TSuccess, TFailure> DecodeResult<TSuccess, TFailure>(this ref SliceDecoder decoder, DecodeFunc<TSuccess> successDecodeFunc, DecodeFunc<TFailure> failureDecodeFunc)
Parameters
decoder
SliceDecoderThe Slice decoder.
successDecodeFunc
DecodeFunc<TSuccess>The decode function for the success type.
failureDecodeFunc
DecodeFunc<TFailure>The decode function for the failure type.
Returns
- Result<TSuccess, TFailure>
The decoded result.
Type Parameters
TSuccess
The type of the success value.
TFailure
The type of the failure value.
DecodeSequenceOfOptionals<T>(ref SliceDecoder, DecodeFunc<T>)
Decodes a sequence where the element type is an optional Slice type (T?).
public static T?[] DecodeSequenceOfOptionals<T>(this ref SliceDecoder decoder, DecodeFunc<T> decodeFunc)
Parameters
decoder
SliceDecoderThe Slice decoder.
decodeFunc
DecodeFunc<T>The decode function for each non-null element of the sequence.
Returns
- T[]
An array of T.
Type Parameters
T
The type of the elements in the array.
Remarks
We return a T? and not a T to avoid ambiguities in the generated code with nullable reference types such as string?.
DecodeSequenceOfOptionals<TSequence, TElement>(ref SliceDecoder, Func<int, TSequence>, DecodeFunc<TElement>)
Decodes a sequence where the element type is an optional Slice type (T?).
public static TSequence DecodeSequenceOfOptionals<TSequence, TElement>(this ref SliceDecoder decoder, Func<int, TSequence> sequenceFactory, DecodeFunc<TElement> decodeFunc) where TSequence : ICollection<TElement>
Parameters
decoder
SliceDecoderThe Slice decoder.
sequenceFactory
Func<int, TSequence>The factory for creating the sequence instance.
decodeFunc
DecodeFunc<TElement>The decode function for each non-null element of the sequence.
Returns
- TSequence
A TSequence.
Type Parameters
TSequence
The type of the returned sequence.
TElement
The type of the elements in the sequence.
DecodeSequence<T>(ref SliceDecoder, Action<T>?)
Decodes a sequence of fixed-size numeric values.
public static T[] DecodeSequence<T>(this ref SliceDecoder decoder, Action<T>? checkElement = null) where T : struct
Parameters
decoder
SliceDecoderThe Slice decoder.
checkElement
Action<T>A delegate used to check each element of the array (optional).
Returns
- T[]
An array of T.
Type Parameters
T
The sequence element type.
DecodeSequence<T>(ref SliceDecoder, DecodeFunc<T>)
Decodes a sequence.
public static T[] DecodeSequence<T>(this ref SliceDecoder decoder, DecodeFunc<T> decodeFunc)
Parameters
decoder
SliceDecoderThe Slice decoder.
decodeFunc
DecodeFunc<T>The decode function for each element of the sequence.
Returns
- T[]
An array of T.
Type Parameters
T
The type of the elements in the array.
DecodeSequence<TSequence, TElement>(ref SliceDecoder, Func<int, TSequence>, DecodeFunc<TElement>)
Decodes a sequence.
public static TSequence DecodeSequence<TSequence, TElement>(this ref SliceDecoder decoder, Func<int, TSequence> sequenceFactory, DecodeFunc<TElement> decodeFunc) where TSequence : ICollection<TElement>
Parameters
decoder
SliceDecoderThe Slice decoder.
sequenceFactory
Func<int, TSequence>The factory for creating the sequence instance.
decodeFunc
DecodeFunc<TElement>The decode function for each element of the sequence.
Returns
- TSequence
A TSequence.
Type Parameters
TSequence
The type of the returned sequence.
TElement
The type of the elements in the sequence.