public static IValueEncoder <T> Bind <T>([NotNull] IUnorderedTypeCodec <T> codec)
            {
                Contract.NotNull(codec, nameof(codec));

                if (codec is IValueEncoder <T> encoder)
                {
                    return(encoder);
                }

                return(new Singleton <T>(
                           (value) => codec.EncodeUnordered(value),
                           (encoded) => codec.DecodeUnordered(encoded)
                           ));
            }
Пример #2
0
            public static IKeyEncoder <T> Bind <T>([NotNull] IUnorderedTypeCodec <T> codec)
            {
                Contract.NotNull(codec, nameof(codec));

                // ReSharper disable once SuspiciousTypeConversion.Global
                if (codec is IKeyEncoder <T> encoder)
                {
                    return(encoder);
                }

                return(new Singleton <T>(
                           (value) => codec.EncodeUnordered(value),
                           (encoded) => codec.DecodeUnordered(encoded)
                           ));
            }
            public static IValueEncoder <T> Bind <T>([NotNull] IUnorderedTypeCodec <T> codec)
            {
                if (codec == null)
                {
                    throw new ArgumentNullException("codec");
                }

                var encoder = codec as IValueEncoder <T>;

                if (encoder != null)
                {
                    return(encoder);
                }

                return(new Singleton <T>(
                           (value) => codec.EncodeUnordered(value),
                           (encoded) => codec.DecodeUnordered(encoded)
                           ));
            }