/// <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)); }
/// <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); }
/// <summary> /// 获取泛型类型函数信息 /// </summary> /// <param name="remoteType">调用代理类型</param> /// <param name="methodName">调用函数名称</param> /// <returns>泛型类型函数信息</returns> private static MethodInfo getGenericTypeMethod(ref fastCSharp.code.remoteType remoteType, string methodName) { Type type = remoteType.Type; if (type.Name == GenericTypeServerName && type.DeclaringType.IsGenericType) { tcpCall tcpCall = fastCSharp.code.typeAttribute.GetAttribute <tcpCall>(type, false, false); if (tcpCall != null && tcpCall.IsGenericTypeServerMethod) { tcpCall = fastCSharp.code.typeAttribute.GetAttribute <tcpCall>(type.DeclaringType, false, true);//cSharp.Default.IsInheritAttribute if (tcpCall != null && tcpCall.IsSetup) { keyValue <Type, fastCSharp.stateSearcher.ascii <MethodInfo> > methods; int version = genericTypeMethodVersion; if (!genericTypeMethods.TryGetValue(type, out methods) || methods.Key != type) { Monitor.Enter(genericTypeMethodLock); try { if (version == genericTypeMethodVersion || !genericTypeMethods.TryGetValue(type, out methods)) { MethodInfo[] methodInfos = type.GetMethods(BindingFlags.Static | BindingFlags.Public); methods = new keyValue <Type, fastCSharp.stateSearcher.ascii <MethodInfo> >(type, new fastCSharp.stateSearcher.ascii <MethodInfo>(methodInfos.getArray(value => value.Name), methodInfos, true)); genericTypeMethods.Add(type, methods); ++genericTypeMethodVersion; } } finally { Monitor.Exit(genericTypeMethodLock); } } return(methods.Value.Get(methodName)); } } } log.Error.Throw(type.fullName() + " 不符合泛型类型服务器端调用", new System.Diagnostics.StackFrame(), false); return(null); }
public static object InvokeGenericTypeMethod(ref fastCSharp.code.remoteType remoteType, string methodName, params object[] parameters) { return(getGenericTypeMethod(ref remoteType, methodName).Invoke(null, parameters)); }
/// <summary> /// 泛型类型函数调用 /// </summary> /// <param name="remoteType">调用代理类型</param> /// <param name="methodName">调用函数名称</param> /// <param name="methodGenericTypes">方法泛型参数集合</param> /// <param name="parameters">调用参数</param> /// <returns>函数返回值</returns> public static object InvokeGenericTypeMethod(ref fastCSharp.code.remoteType remoteType, string methodName, fastCSharp.code.remoteType[] methodGenericTypes, params object[] parameters) { return(getGenericTypeMethod(ref remoteType, methodName).MakeGenericMethod(methodGenericTypes.getArray(value => value.Type)).Invoke(null, parameters)); }