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.

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. Ele deve ser do mesmo tipo da permissão atual.

Retornos

Uma nova permissão que representa a interseção da permissão atual e da permissão especificada. Essa nova permissão é null se a interseção estiver vazia.

Exceções

O parâmetro target não é null e não é uma instância da mesma classe que a permissão atual.

Exemplos

O exemplo de código a seguir demonstra a implementação do Intersect método . Este exemplo de código faz parte de um exemplo maior fornecido para a IPermission classe .

    // 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. Somente uma demanda que passa as duas permissões originais passará pela interseção.

As instruções a seguir são necessárias para serem verdadeiras para todas as implementações do Intersect método. X e Y representam IPermission referências de objeto que não nullsão .

  • X. Intersect(X) retorna um valor igual a X.

  • X. Intersect(Y) retorna o mesmo valor que Y. Intersect(X).

  • X. Intersect(null) retorna null.

Aplica-se a