UIPermission.IsSubsetOf(IPermission) 方法

定义

确定当前权限是否为指定权限的子集。

public:
 override bool IsSubsetOf(System::Security::IPermission ^ target);
public override bool IsSubsetOf (System.Security.IPermission target);
override this.IsSubsetOf : System.Security.IPermission -> bool
Public Overrides Function IsSubsetOf (target As IPermission) As Boolean

参数

target
IPermission

将要测试子集关系的权限。 此权限必须与当前权限属于同一类型。

返回

如果当前权限是指定权限的子集,则为 true;否则为 false

例外

target 参数不为 null,并且与当前权限不属于同一类型。

示例

下面的代码示例演示 了 方法的行为 IsSubsetOf 。 此示例是为 类提供的更大示例的 UIPermission 一部分。

注意

代码示例旨在显示方法的行为,而不是演示其用法。 通常,权限类的方法由安全基础结构使用;它们通常不用于应用程序。

// IsSubsetOf determines whether the current permission is a subset of the specified permission.

void IsSubsetOfDemo()
{
    Console::WriteLine("\n**********************  IsSubsetOf() Demo **********************\n");
    UIPermission ^ uiPerm1 = gcnew UIPermission(UIPermissionWindow::SafeTopLevelWindows);
    UIPermission ^ uiPerm2 = gcnew UIPermission(UIPermissionWindow::SafeSubWindows);

    Console::WriteLine("   {0} is {1}a subset of {2} ", uiPerm1->Window,
                            uiPerm1->IsSubsetOf(uiPerm2)?"":"not ", uiPerm2->Window);

    Console::WriteLine("   {0} is {1}a subset of {2} ", uiPerm2->Window,
                            uiPerm2->IsSubsetOf(uiPerm1)?"":"not ", uiPerm1->Window);

    uiPerm1 = gcnew UIPermission(UIPermissionClipboard::AllClipboard);
    uiPerm2 = gcnew UIPermission(UIPermissionClipboard::OwnClipboard);

    Console::WriteLine("   {0} is {1}a subset of {2} ", uiPerm1->Clipboard,
                            uiPerm1->IsSubsetOf(uiPerm2)?"":"not ", uiPerm2->Clipboard);

    Console::WriteLine("   {0} is {1}a subset of {2} ", uiPerm2->Clipboard,
                            uiPerm2->IsSubsetOf(uiPerm1)?"":"not ", uiPerm1->Clipboard);
}
// 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());
    }
}
' IsSubsetOf determines whether the current permission is a subset of the specified permission.
Private Shared Sub IsSubsetOfDemo()
    Dim uiPerm1 As New UIPermission(UIPermissionWindow.SafeTopLevelWindows)
    Dim uiPerm2 As New UIPermission(UIPermissionWindow.SafeSubWindows)
    CheckIsSubsetOfWindow(uiPerm1, uiPerm2)
    uiPerm1 = New UIPermission(UIPermissionClipboard.AllClipboard)
    uiPerm2 = New UIPermission(UIPermissionClipboard.OwnClipboard)
    CheckIsSubsetOfClipBoard(uiPerm1, uiPerm2)

End Sub

Private Shared Sub CheckIsSubsetOfWindow(ByVal uiPerm1 As UIPermission, ByVal uiPerm2 As UIPermission)
    If uiPerm1.IsSubsetOf(uiPerm2) Then
        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())
    End If

    If uiPerm2.IsSubsetOf(uiPerm1) Then
        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())
    End If

End Sub

Private Shared Sub CheckIsSubsetOfClipBoard(ByVal uiPerm1 As UIPermission, ByVal uiPerm2 As UIPermission)
    If uiPerm1.IsSubsetOf(uiPerm2) Then
        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())
    End If

    If uiPerm2.IsSubsetOf(uiPerm1) Then
        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())
    End If

End Sub

注解

如果当前权限的所有成功要求也针对指定权限成功,则当前权限是指定权限的子集。 也就是说,指定的权限至少包含子集中包含的权限。 若要 IsSubsetOf 返回 trueUIPermissionWindow 当前权限的 和 UIPermissionClipboard 值必须等于或小于指定权限的值。

适用于