Implementing imperative security declaratively using PostSharp
At a recent TechTalk I talked about code access security and how to perform declarative and imperative security demands & requests. There's no doubt declarative security checking is nicer than imperative checking, but not everything can be done declaratively. Say we have the following method: static void writeFile(string filePath)
{
File.WriteAllText("test", filePath);
}
We want to make sure we have permission to write to the filepath. Declaratively, we can request (SecurityAction.RequestMinimum) for an unrestricted FileIOPermission which would ensure that we had write access. But requesting unrestricted IO access is way overkill, since we only need access to select paths.
I got the question,...