예제 #1
0
        public object Read <TT>(bool isArray = false)
        {
            var readers = Utils.InitTypes();

            readers.AddRange(BinaryRuntime.Gets());

            if (isArray)
            {
                var c   = Read <int>().To <int>();
                var ret = new List <TT>();
                for (var i = 0; i < c; i++)
                {
                    ret.Add(Read <TT>().To <TT>());
                }
                return(ret.ToArray());
            }
            else
            {
                if (!readers.ContainsKey(typeof(TT)))
                {
                    throw new NotSupportedException(typeof(TT).Name + " is not supported");
                }
                else
                {
                    return((TT)readers[typeof(TT)].OnRead(this));
                }
            }
        }
예제 #2
0
        public void Write <T>(object value, bool isArray = false)
        {
            var writers = Utils.InitTypes();

            writers.AddRange(BinaryRuntime.Gets());

            if (isArray)
            {
                var v = new List <T>((T[])value);
                Write <int>(v.Count);
                foreach (var vv in v)
                {
                    Write <T>(vv);
                }
            }
            else
            {
                if (!writers.ContainsKey(typeof(T)))
                {
                    throw new NotSupportedException(typeof(T).Name + " is not supported");
                }
                else
                {
                    writers[typeof(T)].OnWrite(this, value);
                }
            }
        }