Beispiel #1
0
        public void WriteArray <T>(List <T> value)
        {
            if (value == null)
            {
                return;
            }

            Type findType = typeof(T);

            if (findType.IsSubclassOf(typeof(MessageBase)))
            {
                findType = typeof(MessageBase);
            }

            bool hasKey = mArrItemCoderMap.ContainsKey(findType);

            if (!hasKey)
            {
                throw new Exception("没有找到对应的解码器:" + findType);
            }

            IArrItemCoder coder = mArrItemCoderMap[findType];
            UInt32        len   = (UInt32)value.Count;

            WriteU32(len);
            for (int i = 0; i < len; i++)
            {
                object valueEx = value[i];
                if (valueEx == null)
                {
                    throw new NullReferenceException("用于编码的列表数据项不能为空");
                }
                coder.Code(this, ref valueEx);
            }
        }
Beispiel #2
0
        public void ReadArray <T>(out List <T> value) where T : new()
        {
            Type findType = typeof(T);

            if (findType.IsSubclassOf(typeof(MessageBase)))
            {
                findType = typeof(MessageBase);
            }

            bool hasKey = mArrItemCoderMap.ContainsKey(findType);

            if (!hasKey)
            {
                throw  new Exception("没有找到对应的解码器:" + findType);
            }

            IArrItemCoder coder = mArrItemCoderMap[findType];
            UInt32        len   = 0;

            ReadU32(ref len);
            value = new List <T>((int)len);
            for (int i = 0; i < len; i++)
            {
                object item;
                coder.Decode <T>(this, out item);
                value.Add((T)item);
            }
        }