mirror of
https://github.com/Jetsparrow/jetherald.git
synced 2026-01-20 23:56:08 +03:00
29 lines
781 B
C#
29 lines
781 B
C#
using System.Reflection;
|
|
|
|
namespace JetHerald.Authorization;
|
|
public static class FlightcheckHelpers
|
|
{
|
|
public static IEnumerable<string> GetUsedPermissions(Type rootType)
|
|
{
|
|
var res = new HashSet<string>();
|
|
var asm = Assembly.GetAssembly(rootType);
|
|
var types = asm.GetTypes();
|
|
var methods = types.SelectMany(t => t.GetMethods());
|
|
|
|
foreach (var t in types)
|
|
{
|
|
if (t.GetCustomAttribute<PermissionAttribute>() is PermissionAttribute perm)
|
|
res.Add(perm.Policy);
|
|
}
|
|
|
|
foreach (var t in methods)
|
|
{
|
|
if (t.GetCustomAttribute<PermissionAttribute>() is PermissionAttribute perm)
|
|
res.Add(perm.Policy);
|
|
}
|
|
|
|
return res.OrderBy(p => p);
|
|
}
|
|
}
|
|
|