12345678910111213141516171819202122232425262728293031323334 |
- using System.Reflection;
- using Luticate2.Auth.Interfaces.Permissions;
- using Microsoft.AspNetCore.Mvc.Controllers;
- using Microsoft.AspNetCore.Mvc.Filters;
-
- namespace Luticate2.Auth.Attributes.EntityAccessors
- {
- public class LuAttrArgumentAccessor : ILuAttrEntityAccessor
- {
- public object GetEntity(ActionExecutingContext context, object id)
- {
- var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
- if (actionDescriptor != null)
- {
- var parameters = actionDescriptor.MethodInfo.GetParameters();
- foreach (var parameter in parameters)
- {
- var attributes = parameter.GetCustomAttributes<LuPermissionArgAttribute>();
- foreach (var attribute in attributes)
- {
- if (attribute.Id == id)
- {
- if (context.ActionArguments.ContainsKey(parameter.Name))
- {
- return context.ActionArguments[parameter.Name];
- }
- }
- }
- }
- }
- return null;
- }
- }
- }
|