// Permit only the permissions in this set.
public virtual void PermitOnly()
{
// Demand the permission first, because we cannot permit it
// for exclusive access if we are not allowed have it at all.
Demand();
// Create a permission set and copy all CA objects into it.
PermissionSet set = new PermissionSet(PermissionState.None);
int posn;
CodeAccessPermission perm;
for (posn = 0; posn < permissions.Count; ++posn)
{
perm = (permissions[posn] as CodeAccessPermission);
if (perm != null)
{
set.AddPermission(perm.Copy());
}
}
// Set the current "PermitOnly" context on the call stack.
CodeAccessPermission.PermitOnly(set, 2);
}