IPermission.Intersect(IPermission) Método

Definição

Cria e retorna uma permissão que é a interseção de permissão atual e da permissão especificada.Creates and returns a permission that is the intersection of the current permission and the specified permission.

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

Parâmetros

target
IPermission

Uma permissão para ter interseção com a permissão atual.A permission to intersect with the current permission. Ele deve ser do mesmo tipo da permissão atual.It must be of the same type as the current permission.

Retornos

IPermission

Uma nova permissão que representa a interseção da permissão atual e da permissão especificada.A new permission that represents the intersection of the current permission and the specified permission. Essa nova permissão é null se a interseção estiver vazia.This new permission is null if the intersection is empty.

Exceções

O parâmetro target não é null e não é uma instância da mesma classe que a permissão atual.The target parameter is not null and is not an instance of the same class as the current permission.

Exemplos

O exemplo de código a seguir demonstra a implementação do Intersect método.The following code example demonstrates implementing the Intersect method. Este exemplo de código faz parte de um exemplo maior fornecido para a IPermission classe.This code example is part of a larger example provided for the IPermission class.

    // Return a new object that contains the intersection 
    // of 'this' and 'target'.
public:
    virtual IPermission^ Intersect(IPermission^ target) override
    {
        // If 'target' is null, return null.
        if (target == nullptr)
        {
            return nullptr;
        }

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

        // If 'this' and 'target' are unrestricted, 
        // return a new unrestricted permission.
        if (specifiedAsUnrestricted && soundPerm->specifiedAsUnrestricted)
        {
            return Clone(true, SoundPermissionState::PlayAnySound);
        }

        // Calculate the intersected permissions. 
        // If there are none, return null.
        SoundPermissionState minimumPermission = (SoundPermissionState)
            Math::Min((int) stateFlags, (int) soundPerm->stateFlags);
        if ((int)minimumPermission == 0)
        {
            return nullptr;
        }

        // Return a new object with the intersected permission value.
        return Clone(false, minimumPermission);
    }
// Return a new object that contains the intersection of 'this' and 'target'.
public override IPermission Intersect(IPermission target)
{
    // If 'target' is null, return null.
    if (target == null) return null;

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

    // If 'this' and 'target' are unrestricted, return a new unrestricted permission.
    if (m_specifiedAsUnrestricted && soundPerm.m_specifiedAsUnrestricted)
        return Clone(true, SoundPermissionState.PlayAnySound);

    // Calculate the intersected permissions. If there are none, return null.
    SoundPermissionState val = (SoundPermissionState)
        Math.Min((Int32)m_flags, (Int32)soundPerm.m_flags);
    if (val == 0) return null;

    // Return a new object with the intersected permission value.
    return Clone(false, val);
}
' Return a new object that contains the intersection of 'this' and 'target'.
Public Overrides Function Intersect(ByVal target As IPermission) As IPermission
    ' If 'target' is null, return null.
    If target Is Nothing Then
        Return Nothing
    End If
    ' Both objects must be the same type.
    Dim soundPerm As SoundPermission = VerifyTypeMatch(target)

    ' If 'this' and 'target' are unrestricted, return a new unrestricted permission.
    If m_specifiedAsUnrestricted AndAlso soundPerm.m_specifiedAsUnrestricted Then
        Return Clone(True, SoundPermissionState.PlayAnySound)
    End If
    ' Calculate the intersected permissions. If there are none, return null.
    Dim val As SoundPermissionState = CType(Math.Min(CType(m_flags, Int32), CType(soundPerm.m_flags, Int32)), SoundPermissionState)
    If val = 0 Then
        Return Nothing
    End If
    ' Return a new object with the intersected permission value.
    Return Clone(False, val)

End Function 'Intersect

Comentários

A interseção de duas permissões é uma permissão que descreve o conjunto de operações que ambos descrevem em comum.The intersection of two permissions is a permission that describes the set of operations they both describe in common. Somente uma demanda que passa as duas permissões originais passará a interseção.Only a demand that passes both original permissions will pass the intersection.

As instruções a seguir precisam ser verdadeiras para todas as implementações do Intersect método.The following statements are required to be true for all implementations of the Intersect method. X e Y representam IPermission referências de objeto que não são null .X and Y represent IPermission object references that are not null.

  • X. Intersect ( X ) retorna um valor igual a X .X.Intersect(X) returns a value equal to X.

  • X. Intersect ( Y ) retorna o mesmo valor de Y . Intersect ( X ).X.Intersect(Y) returns the same value as Y.Intersect(X).

  • X. O Intersect ( null ) retorna null .X.Intersect(null) returns null.

Aplica-se a