Compartir a través de


UIPermission.IsSubsetOf(IPermission) Método

Definición

Determina si el permiso actual es un subconjunto del permiso especificado.

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

Parámetros

target
IPermission

Permiso para probar la relación del subconjunto. Este permiso debe ser del mismo tipo que el permiso actual.

Devoluciones

true si el permiso actual es un subconjunto del permiso especificado; si no, false.

Excepciones

El parámetro target no es null y no es del mismo tipo que el permiso actual.

Ejemplos

En el ejemplo de código siguiente se muestra el comportamiento del IsSubsetOf método . Este ejemplo forma parte de un ejemplo más grande proporcionado para la UIPermission clase .

Nota:

El ejemplo de código está pensado para mostrar el comportamiento del método, no para demostrar su uso. En general, la infraestructura de seguridad utiliza los métodos de las clases de permisos; normalmente no se usan en aplicaciones.

// 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

Comentarios

El permiso actual es un subconjunto del permiso especificado si todas las demandas que se realizan correctamente para el permiso actual también se realizan correctamente para el permiso especificado. Es decir, el permiso especificado contiene al menos los permisos contenidos en el subconjunto. Para IsSubsetOf que devuelva true, los UIPermissionWindow valores y UIPermissionClipboard del permiso actual deben ser iguales o menos permisivos que los valores del permiso especificado.

Se aplica a