Esempio n. 1
0
        public static MSFramework.Function.FunctionDefine GetFunction(this ActionDescriptor actionDescriptor)
        {
            var controllerAction = (ControllerActionDescriptor)actionDescriptor;
            var functionPath     = actionDescriptor.GetActionPath();
            var parameters       = controllerAction.Parameters.Select(x => $"{x.ParameterType.Name} {x.Name}")
                                   .ExpandAndToString();
            var typeName = controllerAction.MethodInfo.DeclaringType?.FullName;
            var name     = string.IsNullOrWhiteSpace(typeName)?
                           $"{controllerAction.MethodInfo.Name}({parameters})":$"{typeName}.{controllerAction.MethodInfo.Name}({parameters})";

            return(new MSFramework.Function.FunctionDefine(name, functionPath, null));
        }
Esempio n. 2
0
        public static Permission GetPermission(this ActionDescriptor actionDescriptor)
        {
            var controllerAction = (ControllerActionDescriptor)actionDescriptor;
            var identification   = actionDescriptor.GetActionPath();
            var parameters       = controllerAction.Parameters.Select(x => $"{x.ParameterType.Name} {x.Name}")
                                   .ExpandAndToString();

            var permissionAttributeData =
                controllerAction.MethodInfo.CustomAttributes.FirstOrDefault(x =>
                                                                            x.AttributeType == typeof(PermissionAttribute));

            if (permissionAttributeData != null)
            {
                return(new Permission
                {
                    Name = permissionAttributeData.NamedArguments?.FirstOrDefault(x => x.MemberName == "Name")
                           .TypedValue.Value?.ToString(),
                    Module = permissionAttributeData.NamedArguments?.FirstOrDefault(x => x.MemberName == "Module")
                             .TypedValue.Value?.ToString(),
                    Description = permissionAttributeData.NamedArguments
                                  ?.FirstOrDefault(x => x.MemberName == "Description")
                                  .TypedValue.Value?.ToString(),
                    Identification = identification
                });
            }
            else
            {
                var name =
                    $"{controllerAction.MethodInfo.DeclaringType?.FullName}.{controllerAction.MethodInfo.Name}({parameters})";
                return(new Permission
                {
                    Name = name,
                    Identification = identification
                });
            }
        }