public static serviceInfo GetServiceInfo(Type type, bool initObjCtor = false) { var a = serviceInfoCache.TryGetValue(type, out var info); if (a) { return(info); } info = new serviceInfo() { ServiceType = type, Attributes = type.GetCustomAttributes().ToList(), }; if (initObjCtor) { info.InstaceCtor = DynamicMethodHelper.CreateCtorFunc <Func <object> >(type, Type.EmptyTypes); } var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance); var methodInfoList = new List <methodInfo>(); foreach (var m in methods) { var mInfo = new methodInfo() { Attributes = m.GetCustomAttributes().ToList(), MethodInfo = m, Parameters = m.GetParameters(), MethodInvoker = DynamicMethodHelper.CreateMethodInvoker(m) }; mInfo.IsAsync = m.ReturnType.Name.StartsWith("Task`1"); if (mInfo.IsAsync) //总是返回同步结果 { mInfo.TaskInvoker = DynamicMethodHelper.TaskResultInvoker <object>(m.ReturnType); var taskType = typeof(AsyncResult <>).MakeGenericType(m.ReturnType.GetGenericArguments()[0]); mInfo.TaskCreater = DynamicMethodHelper.CreateCtorFunc <Func <AsyncResult> >(taskType, new Type[0]); } methodInfoList.Add(mInfo); } info.Methods = methodInfoList; info.ServiceAttribute = type.GetCustomAttribute <ServiceAttribute>() ?? new ServiceAttribute(); apiPrefixCache.TryAdd(info.ServiceAttribute.ApiPrefix, type); serviceInfoCache.TryAdd(type, info); return(info); }
public static serviceInfo GetServiceInfo(Type type) { var info = new serviceInfo() { ServiceType = type, Attributes = type.GetCustomAttributes().ToList() }; var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance); var methodInfoList = new List <methodInfo>(); foreach (var m in methods) { var mInfo = new methodInfo() { Attributes = m.GetCustomAttributes().ToList(), MethodInfo = m, Parameters = m.GetParameters() }; methodInfoList.Add(mInfo); } info.Methods = methodInfoList; return(info); }