namespace MiaoYu.Core.Permission; /// /// 权限工具 /// public class PermissionUtil { /// /// 获取控制器 的 ControllerDescriptorAttribute 特性 /// /// /// public static ControllerDescriptorAttribute? GetControllerDescriptorAttribute(Type type) { var customAttributes = type.GetCustomAttributes(); return (ControllerDescriptorAttribute?)customAttributes.FirstOrDefault(w => w is ControllerDescriptorAttribute); } /// /// 获取控制器 的 ControllerDescriptorAttribute 特性 /// /// /// public static ControllerDescriptorAttribute? GetControllerDescriptorAttribute(ControllerBase controllerBase) { if (controllerBase == null) return default; var customAttributes = controllerBase.GetType().GetCustomAttributes(); return (ControllerDescriptorAttribute?)customAttributes.FirstOrDefault(w => w is ControllerDescriptorAttribute); } /// /// 获取控制器 的 ControllerDescriptorAttribute 特性 /// /// /// public static ControllerDescriptorAttribute? GetControllerDescriptorAttributeByType(Type controllerType) { if (controllerType == null) return default; var customAttributes = controllerType.GetCustomAttributes(); return (ControllerDescriptorAttribute?)customAttributes.FirstOrDefault(w => w is ControllerDescriptorAttribute); } /// /// 获取 Action 描述标记特性 /// /// /// public static ActionDescriptorAttribute? GetActionDescriptorAttribute(ActionDescriptor actionDescriptor) { return (ActionDescriptorAttribute?)actionDescriptor.EndpointMetadata.FirstOrDefault(w => w is ActionDescriptorAttribute); } /// /// 获取当前控制器的显示名称 /// /// /// public static string? GetControllerDisplayName(Type type) { return GetControllerDescriptorAttribute(type)?.DisplayName; } /// /// 获取当前控制器的显示名称 /// /// /// public static string? GetControllerDisplayName(ControllerBase controllerBase) { return GetControllerDescriptorAttribute(controllerBase)?.DisplayName; } }