Here's how I want to use them:
class SecuredModel
{
public SecuredModel() { }
[Permission(Permissions.Read)]
public void restrictedMethod()
{
if (IsPermitted)
{
// code
}
}
}
I have defined here the "Permission" class:
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = true)]
class Permission : System.Attribute
{
private Permissions PermissionsRequired { get; set; }
public bool IsPermitted
{
// some code to check for permissions
}
public Permission(Permissions permissionsRequired)
{
this.PermissionsRequired = permissionsRequired;
}
}
The problem I am having is that I don't know how to use the attributes I've assigned to my methods. I'd like to access them from within the method, is that a possibility? If not, could I instead access them from outside the method? I haven't been able to find this usage of any of the MSDN pages I've looked at, and I've seen some answers on SO, but I feel like a lambda expression is overcomplicating this. It shouldn't be that difficult, right?