You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuAttrArgumentAccessor.cs 1.2KB

12345678910111213141516171819202122232425262728293031323334
  1. using System.Reflection;
  2. using Luticate2.Auth.Interfaces.Permissions;
  3. using Microsoft.AspNetCore.Mvc.Controllers;
  4. using Microsoft.AspNetCore.Mvc.Filters;
  5. namespace Luticate2.Auth.Attributes.EntityAccessors
  6. {
  7. public class LuAttrArgumentAccessor : ILuAttrEntityAccessor
  8. {
  9. public object GetEntity(ActionExecutingContext context, object id)
  10. {
  11. var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
  12. if (actionDescriptor != null)
  13. {
  14. var parameters = actionDescriptor.MethodInfo.GetParameters();
  15. foreach (var parameter in parameters)
  16. {
  17. var attributes = parameter.GetCustomAttributes<LuPermissionArgAttribute>();
  18. foreach (var attribute in attributes)
  19. {
  20. if (attribute.Id == id)
  21. {
  22. if (context.ActionArguments.ContainsKey(parameter.Name))
  23. {
  24. return context.ActionArguments[parameter.Name];
  25. }
  26. }
  27. }
  28. }
  29. }
  30. return null;
  31. }
  32. }
  33. }