Advertisement
sukhdev

ParsePermissions

Apr 27th, 2025
181
0
Never
Not a member of Pastebin yet?Sign Up, it unlocks many cool features!
C# 0.85 KB | Source Code | 00
  1. privatestatic List<ModuleModel> ParsePermissions(Type permissionType)
  2. {
  3.     var modules = permissionType
  4.         .GetNestedTypes()
  5.         .Where(c => c.GetCustomAttribute<ModuleDescriptionAttribute>()!=null)
  6.         .Select(c =>new ModuleModel
  7.         {
  8.             Name = c.Name,
  9.             Description = c.GetCustomAttribute<ModuleDescriptionAttribute>(),
  10.             Permissions = c
  11.             .GetFields(BindingFlags.Public| BindingFlags.Static| BindingFlags.FlattenHierarchy)
  12.             .Where(c => c.FieldType==typeof(string))
  13.             .ToDictionary(c => c.Name, c =>new PermissionModel
  14.             {
  15.                 Name = c.Name,
  16.                 Value= c.GetValue(null)?.ToString(),
  17.                 Description = c.GetCustomAttribute<PermissionDescriptionAttribute>()
  18.             })
  19.         }).ToList();
  20.  
  21.     return modules;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement
close