/// <summary> /// 获取泛型类型函数信息 /// </summary> /// <param name="remoteType">调用代理类型</param> /// <param name="methodName">调用函数名称</param> /// <returns>泛型类型函数信息</returns> public static MethodInfo getGenericTypeMethod(fastCSharp.setup.remoteType remoteType, string methodName) { Type type = remoteType.Type; if (type.Name == genericTypeServerName && type.DeclaringType.IsGenericType) { tcpCall tcpCall = type.customAttribute <tcpCall>(); if (tcpCall != null && tcpCall.IsGenericTypeServerMethod && tcpCall.IsIgnore) { tcpCall = type.DeclaringType.customAttribute <tcpCall>(false, cSharp.Default.IsInheritAttribute); if (tcpCall != null && tcpCall.IsSetup) { keyValue <Type, staticDictionary <string, MethodInfo> > methods; int version = genericTypeMethodVersion; hashCode <Type> hashType = type; if (!genericTypeMethods.TryGetValue(hashType, out methods) || methods.Key != type) { while (Interlocked.CompareExchange(ref genericTypeMethodLock, 1, 0) != 0) { Thread.Sleep(1); } try { if (version == genericTypeMethodVersion || !genericTypeMethods.TryGetValue(hashType, out methods)) { methods = new keyValue <Type, staticDictionary <string, MethodInfo> >(type, new staticDictionary <string, MethodInfo>(type.GetMethods(BindingFlags.Static | BindingFlags.Public), value => value.Name)); genericTypeMethods.Add(hashType, methods); ++genericTypeMethodVersion; } } finally { genericTypeMethodLock = 0; } } return(methods.Value.Get(methodName, null)); } } } log.Default.Throw(type.fullName() + " 不符合泛型类型服务器端调用", false, false); return(null); }
/// <summary> /// 获取泛型回调委托 /// </summary> /// <param name="type">返回值类型</param> /// <param name="callback">回调委托</param> /// <returns>泛型回调委托</returns> public static object GetGenericParameterCallback(fastCSharp.setup.remoteType type, action <fastCSharp.setup.cSharp.tcpBase.asynchronousReturn <object> > callback) { return(((func <action <fastCSharp.setup.cSharp.tcpBase.asynchronousReturn <object> >, object>)Delegate.CreateDelegate(typeof(func <action <fastCSharp.setup.cSharp.tcpBase.asynchronousReturn <object> >, object>), getGenericParameterCallbackMethod.MakeGenericMethod(type.Type)))(callback)); }
/// <summary> /// 泛型类型函数调用 /// </summary> /// <param name="remoteType">调用代理类型</param> /// <param name="methodName">调用函数名称</param> /// <param name="parameters">调用参数</param> /// <returns>函数返回值</returns> public static object InvokeGenericTypeMethod(fastCSharp.setup.remoteType remoteType, string methodName, params object[] parameters) { return(getGenericTypeMethod(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(fastCSharp.setup.remoteType remoteType, string methodName, fastCSharp.setup.remoteType[] methodGenericTypes, params object[] parameters) { return(getGenericTypeMethod(remoteType, methodName).MakeGenericMethod(methodGenericTypes.getArray(value => value.Type)).Invoke(null, parameters)); }