Exemplo n.º 1
0
        /// <summary>
        /// 重写以实现从方法信息中提取模块信息
        /// </summary>
        /// <param name="method">方法信息</param>
        /// <param name="typeInfo">所在类型模块信息</param>
        /// <param name="index">序号</param>
        /// <returns>提取到的模块信息</returns>
        protected override ModuleInfo GetModule(MethodInfo method, ModuleInfo typeInfo, int index)
        {
            ModuleInfoAttribute infoAttr = method.GetAttribute <ModuleInfoAttribute>();
            ModuleInfo          info     = new ModuleInfo()
            {
                Name  = infoAttr.Name ?? method.GetDescription() ?? method.Name,
                Code  = infoAttr.Code ?? method.Name,
                Order = infoAttr.Order > 0 ? infoAttr.Order : index + 1
            };
            string controller = method.DeclaringType?.Name.Replace("Controller", "");

            info.Position = $"{typeInfo.Position}.{controller}";
            //依赖的功能
            string           area = method.DeclaringType.GetAttribute <AreaAttribute>(true)?.RouteValue;
            List <IFunction> dependOnFunctions = new List <IFunction>()
            {
                FunctionHandler.GetFunction(area, controller, method.Name)
            };

            DependOnFunctionAttribute[] dependOnAttrs = method.GetAttributes <DependOnFunctionAttribute>();
            foreach (DependOnFunctionAttribute dependOnAttr in dependOnAttrs)
            {
                string    darea       = dependOnAttr.Area == null ? area : dependOnAttr.Area == string.Empty ? null : dependOnAttr.Area;
                string    dcontroller = dependOnAttr.Controller ?? controller;
                IFunction function    = FunctionHandler.GetFunction(darea, dcontroller, dependOnAttr.Action);
                if (function == null)
                {
                    throw new OsharpException($"功能“{area}/{controller}/{method.Name}”的依赖功能“{darea}/{dcontroller}/{dependOnAttr.Action}”无法找到");
                }
                dependOnFunctions.Add(function);
            }
            info.DependOnFunctions = dependOnFunctions.ToArray();

            return(info);
        }