Exemplo n.º 1
0
        /// <summary>
        /// 获取配置信息
        /// </summary>
        /// <param name="serviceName">TCP调用服务名称</param>
        /// <param name="type">TCP服务器类型</param>
        /// <returns>TCP调用服务器端配置信息</returns>
        public static tcpServer GetTcpCallConfig(string serviceName, Type type = null)
        {
            tcpServer attribute = new tcpServer();

            if (type != null)
            {
                tcpCall tcpCall = fastCSharp.code.typeAttribute.GetAttribute <tcpCall>(type, false, true);
                if (tcpCall != null)
                {
                    attribute.CopyFrom(tcpCall);
                }
            }
            attribute = fastCSharp.config.pub.LoadConfig(attribute, serviceName);
            if (attribute.Service == null)
            {
                attribute.Service = serviceName;
            }
            return(attribute);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 获取TCP调用泛型函数集合
 /// </summary>
 /// <param name="type">目标类型</param>
 /// <returns>TCP调用泛型函数集合</returns>
 public static Dictionary <genericMethod, MethodInfo> GetGenericMethods(Type type)
 {
     if (type != null)
     {
         tcpCall tcpCall = fastCSharp.code.typeAttribute.GetAttribute <tcpCall>(type, false, true);//cSharp.Default.IsInheritAttribute
         if (tcpCall != null && tcpCall.IsSetup)
         {
             Dictionary <genericMethod, MethodInfo> values = dictionary.Create <genericMethod, MethodInfo>();
             foreach (code.methodInfo method in code.methodInfo.GetMethods <tcpCall>(type, tcpCall.MemberFilter, false, tcpCall.IsAttribute, tcpCall.IsBaseTypeAttribute, tcpCall.IsInheritAttribute))
             {
                 if (method.Method.IsGenericMethod)
                 {
                     values.Add(new genericMethod(method.Method), method.Method);
                 }
             }
             return(values);
         }
     }
     return(null);
 }
Exemplo n.º 3
0
        /// <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);
        }