IPermission.Intersect(IPermission) Método

Definición

Crea y devuelve un permiso que es la intersección del permiso actual y el permiso especificado.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);
abstract member Intersect : System.Security.IPermission -> System.Security.IPermission
Public Function Intersect (target As IPermission) As IPermission

Parámetros

target
IPermission

Permiso para formar intersección con el permiso actual.A permission to intersect with the current permission. Debe ser del mismo tipo que el permiso actual.It must be of the same type as the current permission.

Devoluciones

IPermission

Nuevo permiso que representa la intersección del permiso actual y del permiso especificado.A new permission that represents the intersection of the current permission and the specified permission. Este nuevo permiso es null si la intersección está vacía.This new permission is null if the intersection is empty.

Excepciones

El parámetro target no es null y no es una instancia de la misma clase que el permiso actual.The target parameter is not null and is not an instance of the same class as the current permission.

Ejemplos

En el ejemplo de código siguiente se muestra cómo implementar el método Intersect.The following code example demonstrates implementing the Intersect method. Este ejemplo de código forma parte de un ejemplo más extenso proporcionado para la clase IPermission.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

Comentarios

La intersección de dos permisos es un permiso que describe el conjunto de operaciones que describen en común.The intersection of two permissions is a permission that describes the set of operations they both describe in common. Solo una petición que pase ambos permisos originales pasará la intersección.Only a demand that passes both original permissions will pass the intersection.

Deben cumplirse las siguientes instrucciones para todas las implementaciones del método Intersect.The following statements are required to be true for all implementations of the Intersect method. X y Y representan IPermission referencias de objeto que no se null.X and Y represent IPermission object references that are not null.

  • X. Intersect (X) devuelve un valor igual a X.X.Intersect(X) returns a value equal to X.

  • X. Intersect (Y) devuelve el mismo valor que Y. Intersect (X).X.Intersect(Y) returns the same value as Y.Intersect(X).

  • X. Intersect (null) devuelve null.X.Intersect(null) returns null.

Se aplica a