SecurityDescriptorUtils.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Linq;
  3. using InABox.Clients;
  4. namespace InABox.Core
  5. {
  6. public static class SecurityDescriptorUtils
  7. {
  8. public static bool IsSupported(Type type)
  9. {
  10. var entities = type.GetInheritedGenericTypeArguments().ToArray();
  11. if (entities.Length > 1)
  12. return ClientFactory.IsSupported(entities.Skip(1).ToArray());
  13. return true;
  14. }
  15. public static string Type(Type type)
  16. {
  17. type = type.BaseType?.GetGenericArguments().FirstOrDefault();
  18. if (type != null)
  19. {
  20. var caption = type.GetCustomAttributes(typeof(Caption), true).FirstOrDefault() as Caption;
  21. return caption != null ? caption.Text : type.EntityName();
  22. }
  23. return "General";
  24. }
  25. public static string Code(Type type)
  26. {
  27. return type.EntityName().Split('.').Last();
  28. }
  29. public static string Description(Type type)
  30. {
  31. var caption = type.GetCustomAttributes(typeof(Caption), true).FirstOrDefault() as Caption;
  32. return caption != null ? caption.Text : type.EntityName();
  33. }
  34. }
  35. }