Is it possible to consolidate code access security attribute (even if it means imperative method) so I can have something like this in my code?
void WriteToFileAndAccessNetwork()
{
EnterPermission(Perm.File | Perm.Network);
// Do file IO
// Do computation
// Do network operation
LeavePermission(Perm.File | Perm.Network);
}
My program will start with all permissions, but main function will start with zero permission. I will Assert permission only when I need it in the functions that really need them. I am looking for a easy programmatic construct.
The problem I have is, the FileIOPermission.Assert() I make in EnterPermission() remains valid only within EnterPermission function call. As soon as I exit EnterPermission I lose the permission.
Any other ideas?
I dont want to have a long list of declarative attributes above every method and make my code unreadable.