/// <summary> /// 获取TCP调用泛型函数集合 /// </summary> /// <param name="type">目标类型</param> /// <returns>TCP调用泛型函数集合</returns> public static Dictionary <genericMethod, MethodInfo> GetGenericMethods(Type type) { if (type != null) { tcpCall tcpCall = type.customAttribute <tcpCall>(false, cSharp.Default.IsInheritAttribute); if (tcpCall != null && tcpCall.IsSetup) { Dictionary <genericMethod, MethodInfo> values = new Dictionary <genericMethod, MethodInfo>(); foreach (methodInfo method in methodInfo.GetMethods <tcpCall>(type, tcpCall.filter, false, tcpCall.IsAttribute, tcpCall.IsBaseTypeAttribute, tcpCall.IsInheritAttribute)) { if (method.Method.IsGenericMethod) { values.Add(new genericMethod(method.Method), method.Method); } } return(values); } } return(null); }
/// <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); }