UIPermission.IsSubsetOf(IPermission) Method

Definition

Determines whether the current permission is a subset of the specified permission.

public override bool IsSubsetOf (System.Security.IPermission target);

Parameters

target
IPermission

A permission to test for the subset relationship. This permission must be the same type as the current permission.

Returns

true if the current permission is a subset of the specified permission; otherwise, false.

Exceptions

The target parameter is not null and is not of the same type as the current permission.

Examples

The following code example shows the behavior of the IsSubsetOf method. This example is part of a larger example provided for the UIPermission class.

Nota

The code example is intended to show the behavior of the method, not to demonstrate its use. In general, the methods of permission classes are used by the security infrastructure; they are not typically used in applications.

// IsSubsetOf determines whether the current permission is a subset of the specified permission.
private static void IsSubsetOfDemo()
{
    UIPermission uiPerm1 = new UIPermission(UIPermissionWindow.SafeTopLevelWindows);
    UIPermission uiPerm2 = new UIPermission(UIPermissionWindow.SafeSubWindows);
    CheckIsSubsetOfWindow(uiPerm1, uiPerm2);
    uiPerm1 = new UIPermission(UIPermissionClipboard.AllClipboard);
    uiPerm2 = new UIPermission(UIPermissionClipboard.OwnClipboard);
    CheckIsSubsetOfClipBoard(uiPerm1, uiPerm2);
}
private static void CheckIsSubsetOfWindow(UIPermission uiPerm1, UIPermission uiPerm2)
{
    if (uiPerm1.IsSubsetOf(uiPerm2))
    {
        Console.WriteLine(uiPerm1.Window.ToString() + " is a subset of " +
            uiPerm2.Window.ToString());
    }
    else
    {
        Console.WriteLine(uiPerm1.Window.ToString() + " is not a subset of " +
            uiPerm2.Window.ToString());
    }
    if (uiPerm2.IsSubsetOf(uiPerm1))
    {
        Console.WriteLine(uiPerm2.Window.ToString() + " is a subset of " +
            uiPerm1.Window.ToString());
    }
    else
    {
        Console.WriteLine(uiPerm2.Window.ToString() + " is not a subset of " +
            uiPerm1.Window.ToString());
    }
}
private static void CheckIsSubsetOfClipBoard(UIPermission uiPerm1, UIPermission uiPerm2)
{
    if (uiPerm1.IsSubsetOf(uiPerm2))
    {
        Console.WriteLine(uiPerm1.Clipboard.ToString() + " is a subset of " +
            uiPerm2.Clipboard.ToString());
    }
    else
    {
        Console.WriteLine(uiPerm1.Clipboard.ToString() + " is not a subset of " +
            uiPerm2.Clipboard.ToString());
    }
    if (uiPerm2.IsSubsetOf(uiPerm1))
    {
        Console.WriteLine(uiPerm2.Clipboard.ToString() + " is a subset of " +
            uiPerm1.Clipboard.ToString());
    }
    else
    {
        Console.WriteLine(uiPerm2.Clipboard.ToString() + " is not a subset of " +
            uiPerm1.Clipboard.ToString());
    }
}

Remarks

The current permission is a subset of the specified permission if all demands that succeed for the current permission also succeed for the specified permission. That is, the specified permission contains at least the permissions contained in the subset. For IsSubsetOf to return true, both the UIPermissionWindow and UIPermissionClipboard values of the current permission must be equal to or less permissive than the values of the specified permission.

Applies to

Produto Versões
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9