Example #1
0
        public static HashSet <T> BiserDecodeHashSet <T>(this byte[] enc)
        {
            if (enc == null)
            {
                return(null);
            }

            var t1      = (HashSet <T>)GetInstanceCreator(typeof(HashSet <T>))();
            var decoder = new Decoder(enc);
            var f       = GetTypeOfCollection <T>();

            decoder.GetCollection(() => { return((T)f.Item2(decoder)); }, t1, false);
            return(t1);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        static Tuple <Action <Encoder, object>, Func <Decoder, object> > GetTypeOfCollection <T>()
        {
            Type t = typeof(T);
            Tuple <Action <Encoder, object>, Func <Decoder, object> > f = null;

            if (dCoders.TryGetValue(t, out f))
            {
                return(f);
            }

            if (TIEncoder.IsAssignableFrom(t))
            {
                Func <Decoder, object> df = null;
                if (TIDecoder.IsAssignableFrom(t))
                {
                    df = (d) => { return((T)(((IDecoder)GetInstanceCreator(typeof(T))()).BiserDecodeToObject(d))); }
                }
                ;
                else
                {
                    df = (d) => { throw new Exception($"Biser: type {t.ToString()} doesn't implement IDecoder"); }
                };

                f = new Tuple <Action <Encoder, object>, Func <Decoder, object> >(
                    (e, o) => { e.Add((IEncoder)o); }
                    ,
                    df
                    );

                lock (lock_dCoders)
                    dCoders[t] = f;
                return(f);
            }

            FillDecoder();

            if (dCoders.TryGetValue(t, out f))
            {
                return(f);
            }

            throw new Exception($"Biser: type {t.ToString()} doesn't implement IEncoder");
        }