예제 #1
0
 public MethodInfo GetActionMethod(string providerName, string actionName)
 {
     if (dictModuleProviders.ContainsKey(providerName))
     {
         System.RuntimeTypeHandle providerHandle  = dictModuleProviders[providerName];
         MethodHandleInfo[]       actionHandleArr = dictProviderMethods[providerHandle];
         MethodHandleInfo         actionInfo      = actionHandleArr.FirstOrDefault(p => p.MethodName == actionName);
         if (actionInfo == null)
         {
             throw new Exception("未找到名称为 " + actionName + " 并且返回值是IActionResult 类型的方法");
         }
         return((MethodInfo)MethodInfo.GetMethodFromHandle(actionInfo.MethodHandle));
     }
     throw new Exception("未找到名称为" + providerName + " 的模块提供程序,请检查此类型是否在 ModuleRegistration 注册。");
 }
예제 #2
0
        // public IModuleRuntime ModuleRuntime { get; set; }

        public void AddProvider(IModuleProvider provider)
        {
            System.RuntimeTypeHandle providerHandle = provider.GetType().TypeHandle;
            dictModuleProviders.Add(provider.PrividerName, providerHandle);
            //反射出所有结果为 IActionResult类型的方法

            List <MethodHandleInfo> actionMethods = new List <MethodHandleInfo>();

            foreach (MethodInfo method in provider.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public))
            {
                if (method.ReturnType.GetInterfaces().Contains(typeof(IActionResult)))
                {
                    MethodHandleInfo info = new MethodHandleInfo();
                    info.MethodHandle = method.MethodHandle;
                    info.MethodName   = method.Name;
                    actionMethods.Add(info);
                }
            }

            dictProviderMethods.Add(providerHandle, actionMethods.ToArray());
        }