System.Security.CodeAccessPermission.PermitOnly C# (CSharp) Method

PermitOnly() public method

public PermitOnly ( ) : void
return void
        public void PermitOnly() { throw new PlatformNotSupportedException(); }
        public override string ToString() => base.ToString();

Usage Example

Example #1
0
        // 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);
        }