IPermission.IsSubsetOf(IPermission) Metodo

Definizione

Determina se l'autorizzazione corrente è un subset di quella specificata.

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

Parametri

target
IPermission

Autorizzazione da testare per la relazione del subset. Questa autorizzazione deve essere dello stesso tipo di quella corrente.

Restituisce

true se l'autorizzazione corrente è un subset di quella specificata; in caso contrario, false.

Eccezioni

Il parametro target non è null e non è dello stesso tipo dell'autorizzazione corrente.

Esempio

Nell'esempio di codice seguente viene illustrato l'implementazione del IsSubsetOf metodo. Questo esempio di codice fa parte di un esempio più grande fornito per la IPermission classe.

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

Commenti

L'autorizzazione corrente è un subset dell'autorizzazione specificata se l'autorizzazione corrente specifica un set di operazioni interamente contenuto dall'autorizzazione specificata. Ad esempio, un'autorizzazione che rappresenta l'accesso a C:\example.txt è un subset di un'autorizzazione che rappresenta l'accesso a C:\. Se questo metodo restituisce true, l'autorizzazione corrente non rappresenta più l'accesso alla risorsa protetta rispetto all'autorizzazione specificata.

Per tutte le implementazioni del IsSubsetOf metodo sono necessarie le istruzioni seguenti. X, Ye Z rappresentano IPermission oggetti che non nullsono .

  • X. IsSubsetOf(X) restituisce true.

  • X. IsSubsetOf(Y) restituisce lo stesso valore di Y. IsSubsetOf(X) se e solo se X e Y rappresentano lo stesso set di autorizzazioni.

  • Se X. IsSubsetOf(Y) e Y. IsSubsetOf(Z) restituisce true, X. IsSubsetOf(Z) restituisce true.

Se X rappresenta un oggetto vuoto IPermission con uno stato di autorizzazione di None e Y rappresenta un IPermission oggetto che è null, X. IsSubsetOf(Y) restituisce true. Se Z è anche un'autorizzazione vuota, l'operazione Xdel set composto . Union(Z). IsSubsetOf(Y) restituisce true anche perché l'unione di due autorizzazioni vuote è un'autorizzazione vuota.

Si applica a