IPermission.IsSubsetOf(IPermission) Metoda

Definicja

Określa, czy bieżące uprawnienie jest podzbiorem określonego uprawnienia.

public:
 bool IsSubsetOf(System::Security::IPermission ^ target);
public bool IsSubsetOf (System.Security.IPermission? target);
public bool IsSubsetOf (System.Security.IPermission target);
abstract member IsSubsetOf : System.Security.IPermission -> bool
Public Function IsSubsetOf (target As IPermission) As Boolean

Parametry

target
IPermission

Uprawnienie, które ma zostać przetestowane dla relacji podzestawu. To uprawnienie musi być tego samego typu co bieżące uprawnienie.

Zwraca

true jeśli bieżące uprawnienie jest podzbiorem określonego uprawnienia; w przeciwnym razie , false.

Wyjątki

Parametr target nie null jest i nie jest tego samego typu co bieżące uprawnienie.

Przykłady

Poniższy przykład kodu przedstawia implementację IsSubsetOf metody. Ten przykład kodu jest częścią większego przykładu podanego IPermission dla klasy.

    // Called by the Demand method: returns true 
    // if 'this' is a subset of 'target'.
public:
    virtual bool IsSubsetOf(IPermission^ target) override
    {
        // If 'target' is null and this permission allows nothing, 
        // return true.
        if (target == nullptr)
        {
            return (int)stateFlags == 0;
        }

        // Both objects must be the same type.
        SoundPermission^ soundPerm = VerifyTypeMatch(target);

        // Return true if the permissions of 'this' 
        // is a subset of 'target'.
        return stateFlags <= soundPerm->stateFlags;
    }
// Called by the Demand method: returns true if 'this' is a subset of 'target'.
public override Boolean IsSubsetOf(IPermission target)
{
    // If 'target' is null and this permission allows nothing, return true.
    if (target == null) return m_flags == 0;

    // Both objects must be the same type.
    SoundPermission soundPerm = VerifyTypeMatch(target);

    // Return true if the permissions of 'this' is a subset of 'target'.
    return m_flags <= soundPerm.m_flags;
}
' Called by the Demand method: returns true if 'this' is a subset of 'target'.
Public Overrides Function IsSubsetOf(ByVal target As IPermission) As [Boolean]
    ' If 'target' is null and this permission allows nothing, return true.
    If target Is Nothing Then
        Return m_flags = 0
    End If
    ' Both objects must be the same type.
    Dim soundPerm As SoundPermission = VerifyTypeMatch(target)

    ' Return true if the permissions of 'this' is a subset of 'target'.
    Return m_flags <= soundPerm.m_flags

End Function 'IsSubsetOf

Uwagi

Bieżące uprawnienie jest podzbiorem określonego uprawnienia, jeśli bieżące uprawnienie określa zestaw operacji, które są całkowicie zawarte przez określone uprawnienie. Na przykład uprawnienie reprezentujące dostęp do C:\example.txt jest podzbiorem uprawnienia reprezentującego dostęp do C:\. Jeśli ta metoda zwróci truewartość , bieżące uprawnienie nie reprezentuje więcej dostępu do chronionego zasobu niż określone uprawnienie.

W przypadku wszystkich implementacji metody wymagane są następujące instrukcje IsSubsetOf . X, Yi Z reprezentują IPermission obiekty, które nie nullsą .

  • X. Funkcja IsSubsetOf(X) zwraca wartość true.

  • X. Funkcja IsSubsetOf(Y) zwraca tę samą wartość co Y. IsSubsetOf(X) jeśli i tylko wtedy, gdy X i Y reprezentują ten sam zestaw uprawnień.

  • Jeśli X. IsSubsetOf(Y) i Y. IsSubsetOf(Z) zwraca truewartość , X. Funkcja IsSubsetOf(Z) zwraca wartość true.

Jeśli X reprezentuje pusty IPermission obiekt ze stanem uprawnień i Y reprezentuje IPermission obiekt o nullwartości None , X. Funkcja IsSubsetOf(Y) zwraca wartość true. Jeśli Z jest również pustym uprawnieniem, operacja Xzestawu złożonego . Union(Z). Funkcja IsSubsetOf(Y) zwraca również, true ponieważ związek dwóch pustych uprawnień jest pustym uprawnieniem.

Dotyczy