예제 #1
0
            /// <summary>
            /// 反序列化未知类型数据
            /// </summary>
            /// <param name="memberIndex">成员索引</param>
            /// <returns>数组数据</returns>
            protected valueType unknown <valueType>(int memberIndex)
            {
                int length = *(int *)(Read = dataStart + members[memberIndex]);

                if (length == fastCSharp.emit.binarySerializer.NullValue)
                {
                    return(default(valueType));
                }
                if (length <= 0)
                {
                    return((valueType)points[length]);
                }
                int point = (int)(Read - dataStart);

                if (*(int *)(Read += sizeof(int)) == fastCSharp.emit.binarySerializer.NullValue)
                {
                    Read += sizeof(int);
                    return(serialize.deSerialize <valueType> .GetVersionMemerMap(this, point));
                }
                fastCSharp.code.remoteType remoteType = new fastCSharp.code.remoteType();
                if (remoteType.DeSerialize(this))
                {
                    Type type = remoteType.Type;
                    if (typeof(valueType) != typeof(object) && !type.isInherit(typeof(valueType)))
                    {
                        log.Default.Throw(type.fullName() + " 不继承 " + typeof(valueType).fullName() + " ,无法反序列化", false, false);
                    }
                    return((valueType)serializeBase.unknownValue.GetValue(typeof(valueType), type, ((Func <serialize.dataDeSerializer, object>)Delegate.CreateDelegate(typeof(Func <serialize.dataDeSerializer, object>), unknownNotNullMethod.MakeGenericMethod(serializeBase.unknownValue.GetGenericType(type))))(this)));
                }
                log.Default.Throw("remoteType 反序列化失败", true, false);
                return(default(valueType));
            }
예제 #2
0
            /// <summary>
            /// 序列化接口数据
            /// </summary>
            /// <typeparam name="valueType">数据类型</typeparam>
            /// <param name="memberIndex">成员索引</param>
            /// <param name="newValue">获取新数据委托</param>
            /// <returns>序列化接口数据</returns>
            protected valueType iSerialize <valueType>(int memberIndex, Func <valueType> newValue) where valueType : serialize.ISerialize
            {
                int length = *(int *)(Read = dataStart + members[memberIndex]);

                if (length == fastCSharp.emit.binarySerializer.NullValue)
                {
                    return(default(valueType));
                }
                if (length <= 0)
                {
                    return((valueType)points[length]);
                }
                int       point = (int)(Read - dataStart);
                valueType value;

                if (*(int *)(Read += sizeof(int)) == fastCSharp.emit.binarySerializer.NullValue)
                {
                    Read += sizeof(int);
                    value = newValue != null?newValue() : fastCSharp.emit.constructor <valueType> .New();
                }
                else
                {
                    fastCSharp.code.remoteType remoteType = new fastCSharp.code.remoteType();
                    if (remoteType.DeSerialize(this))
                    {
                        Type type = remoteType.Type;
                        if (!type.isInherit(typeof(valueType)))
                        {
                            log.Default.Throw(type.fullName() + " 不继承 " + typeof(valueType).fullName() + " ,无法反序列化", false, false);
                        }
                        value = (valueType)fastCSharp.emit.constructor.Get(type);
                    }
                    else
                    {
                        log.Default.Throw("remoteType 反序列化失败", true, false);
                        value = default(valueType);
                    }
                }
                if (isReferenceMember)
                {
                    points.Add(-point, value);
                }
                value.DeSerialize(this);
                return(value);
            }