Пример #1
0
        public void MergeFrom(ref object value, IStream ms)
        {
            if (ms.ReadByte() == 0)
            {
                value = null;
                return;
            }

            int count = ms.ReadVarInt32();
            var dic   = (IDictionary)value;

            if (value == null)
            {
                value = System.Activator.CreateInstance(type, count);
                dic   = (IDictionary)value;
            }

            for (int i = 0; i < count; ++i)
            {
                object keyValue   = IL.Help.Create(keyType);
                object valueValue = IL.Help.Create(valueType);

                RLStream.MergeFrom(keyTypeSerialize, ms, ref keyValue);
                RLStream.MergeFrom(valueTypeSerialize, ms, ref valueValue);

                dic[keyValue] = valueValue;
            }
        }
Пример #2
0
        void ITypeSerialize.MergeFrom(ref object value, IStream stream)
        {
            byte flag = stream.ReadByte();

            if (flag == 0)
            {
                value = null;
                return;
            }

            byte flagType = stream.ReadByte();
            int  lenght   = stream.ReadVarInt32();

            bool isTypeTrue = flagType == elementTypeSerialize.typeFlag; // 类型是否一致
            var  array      = value as IList;

            if (isTypeTrue && (array == null || array.Count != lenght))
            {
                array = Create(lenght);
                value = array;
            }

            if (isTypeTrue)
            {
                for (int i = 0; i < lenght; ++i)
                {
                    object v = array[i];
                    RLStream.MergeFrom(elementTypeSerialize, stream, ref v);
                    try
                    {
                        array[i] = v;
                    }
                    catch (System.Exception ex)
                    {
                        L.LogException(ex);
                    }
                }
            }
            else
            {
                for (int i = 0; i < lenght; ++i)
                {
                    RLStream.Next(stream);
                }
            }
        }