IPermission.IsSubsetOf(IPermission) Método

Definição

Determina se a permissão atual é um subconjunto da permissão especificada.

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

Parâmetros

target
IPermission

Uma permissão que deve ser testada quanto à relação de subconjunto. Essa permissão deve ser do mesmo tipo da permissão atual.

Retornos

true se a permissão atual for um subconjunto da permissão especificada; caso contrário, false.

Exceções

O parâmetro target não é null e não é do mesmo tipo que a permissão atual.

Exemplos

O exemplo de código a seguir demonstra a implementação do IsSubsetOf método . Este exemplo de código faz parte de um exemplo maior fornecido para a 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

Comentários

A permissão atual será um subconjunto da permissão especificada se a permissão atual especificar um conjunto de operações totalmente contido pela permissão especificada. Por exemplo, uma permissão que representa o acesso a C:\example.txt é um subconjunto de uma permissão que representa o acesso a C:\. Se esse método retornar true, a permissão atual não representará mais acesso ao recurso protegido do que a permissão especificada.

As instruções a seguir precisam ser verdadeiras para todas as implementações do IsSubsetOf método . X, Ye Z representam IPermission objetos que não nullsão .

  • X. IsSubsetOf(X) retorna true.

  • X. IsSubsetOf(Y) retorna o mesmo valor que Y. IsSubsetOf(X) se e somente se X e Y representarem o mesmo conjunto de permissões.

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

Se X representa um objeto vazio IPermission com um estado de permissão de None e Y representa um IPermission objeto que é null, X. IsSubsetOf(Y) retorna true. Se Z também for uma permissão vazia, a operação Xde conjunto composto . Union(Z). IsSubsetOf(Y) também retorna true porque a união de duas permissões vazias é uma permissão vazia.

Aplica-se a