private static RemoteMethodInfo GetRemoteMethod(MethodInfo method) { string serviceKey = SecurityUtility.HashObject(method.DeclaringType); RemoteMethodAttribute rmAttribute = method.GetCustomAttributes(typeof(RemoteMethodAttribute), true)[0] as RemoteMethodAttribute; return(new RemoteMethodInfo(SecurityUtility.HashObject(method), serviceKey, method.Name, rmAttribute.Description, rmAttribute.Offline, method, String.Empty)); }
/// <summary> /// 检查指定类型的服务并根据自定义属性标签在系统中进行注册 /// </summary> /// <param name="type">服务类型</param> public void InspectService(Type type) { if (type.IsDefined(typeof(RemoteServiceAttribute), true)) { // 通过服务属性标签来注册服务 RemoteServiceAttribute serviceAttribute = type.GetCustomAttributes(typeof(RemoteServiceAttribute), true)[0] as RemoteServiceAttribute; string serviceKey = SecurityUtility.HashObject(type); RegisterService(serviceKey, type.Name, serviceAttribute.Description, serviceAttribute.ServiceType, type, serviceAttribute.ServiceScope); // 检查所有方法并注册 MethodInfo[] methods = type.GetMethods(); foreach (MethodInfo method in methods) { MethodInfo mi = method; if (method.IsGenericMethod) { mi = method.GetGenericMethodDefinition(); } if (mi.IsDefined(typeof(RemoteMethodAttribute), true)) { string dataUpdateEvent = null; if (mi.IsDefined(typeof(ClientCacheAttribute), true)) { if (mi.ReturnType == typeof(void)) { logger.Warn("方法 [" + mi.Name + "] 定义了 [ClientCacheAttribute] 特性,但是却没有返回值,已被忽略。"); } else { ClientCacheAttribute cacheAttribute = mi.GetCustomAttributes(typeof(ClientCacheAttribute), true)[0] as ClientCacheAttribute; dataUpdateEvent = cacheAttribute.DataUpdateEvent; } } // 注册方法 RemoteMethodAttribute rmAttribute = mi.GetCustomAttributes(typeof(RemoteMethodAttribute), true)[0] as RemoteMethodAttribute; RegisterFunction(SecurityUtility.HashObject(mi), serviceKey, mi.Name, rmAttribute.Description, rmAttribute.Offline, mi, dataUpdateEvent); } else if (method.IsDefined(typeof(ClientCacheAttribute), true)) { logger.Warn("方法 [" + method.Name + "] 定义了 [ClientCacheAttribute] 特性,但是却没有定义 [RemoteMethodAttribute],已被忽略。"); } } } }