public HasPermissionAttribute(Permissions permission) : base(((int)permission).ToString())
{
}
I want to dynamically check for permissions. Right now I have one single enum having multiple options inside. With that I can use [HasPermission(Permissions.SomePermission)] with the controller and dynamic policy creation does the rest checking if someone has such permission or not.
BUT, it would be nice if I could have more than one enum containing permissions. I could then split permissions into domains, and for example in the future could split the application into domain parts being modules encapsulated inside .dll with their own models, controllers and permissions that main application does not need to know about - but is able to check them anyway by having their values.
So I have such attribute that I could give to Enum that I want to mark as permission container.
[AttributeUsage(AttributeTargets.Enum, AllowMultiple = false)]
public class PermissionsEnumAttribute : Attribute
{
}
I can give it to such enum and dynamically find enums that are marked as permission containers, but how can I preserve ability of IntelliSense to help me? It would be best if HasPermissionAttribute accepted any enum having PermissionEnumAttribute and also giving me some hints what I can actually use.
Is it possible to achieve something like that or I would rather need to use different approach? The main goal is to be able to use [HasPermission] because it's very convinient way to check if someone can access certain controller. Enums were my primary choice as they have autoincremented numeric value that can serve as primary key in code-first approach, so I can just add more options inside and IntelliSense will help me with the rest.