public CombinedDecoder Add(ICustomDecoder decoder) { if (decoder is null) { throw new ArgumentNullException(nameof(decoder)); } return(new CombinedDecoder(_decoders.Concat(new[] { decoder }))); }
/// <summary> /// This will add a custom decoders to any that are already registered /// </summary> public MsgPack5DecoderOptions AddCustomDecoder(ICustomDecoder decoder) { if (decoder is null) { throw new ArgumentNullException(nameof(decoder)); } ICustomDecoder newCombinedDecoder; if (CustomDecoderIfAny is null) { newCombinedDecoder = decoder; } else if (CustomDecoderIfAny is CombinedDecoder combinedDecoder) { newCombinedDecoder = combinedDecoder.Add(decoder); } else { newCombinedDecoder = new CombinedDecoder(new[] { CustomDecoderIfAny, decoder }); } return(new MsgPack5DecoderOptions(newCombinedDecoder, EnableImplicitCasts)); }
/// <summary> /// This will replace any registered custom decoders /// </summary> public MsgPack5DecoderOptions WithCustomDecoder(ICustomDecoder decoder) => new MsgPack5DecoderOptions(decoder, EnableImplicitCasts);
} = new MsgPack5DecoderOptions(DateTimeDecoder.Instance, enableImplicitCasts: false); // The .NET library includes its custom DateTime decoder by default and does not enable implicit (or any) casts private MsgPack5DecoderOptions(ICustomDecoder customDecoder, bool enableImplicitCasts) { CustomDecoderIfAny = customDecoder; EnableImplicitCasts = enableImplicitCasts; }