IPermission.Union(IPermission) Método

Definición

Crea un permiso que es la unión del permiso actual y el permiso especificado.

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

Parámetros

target
IPermission

Permiso para combinar con el permiso actual. Debe ser del mismo tipo que el permiso actual.

Devoluciones

Nuevo permiso que representa la unión del permiso actual y el permiso especificado.

Excepciones

El parámetro target no es null y no es del mismo tipo que el permiso actual.

Ejemplos

En el ejemplo de código siguiente se muestra cómo implementar el Union método . Este ejemplo de código es parte de un ejemplo más grande proporcionado para la clase IPermission.

    // Return a new object that contains the union of 'this' and 'target'.
    // Note: You do not have to implement this method. 
    // If you do not, the version
    // in CodeAccessPermission does this:
    //    1. If target is not null, a NotSupportedException is thrown.
    //    2. If target is null, then Copy is called and 
    //       the new object is returned.
public:
    virtual IPermission^ Union(IPermission^ target) override
    {
        // If 'target' is null, then return a copy of 'this'.
        if (target == nullptr)
        {
            return Copy();
        }

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

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

        // Return a new object with the calculated, unioned permission value.
        return Clone(false, (SoundPermissionState)
            Math::Max((int) stateFlags, (int) soundPerm->stateFlags));
    }
// Return a new object that contains the union of 'this' and 'target'.
// Note: You do not have to implement this method. If you do not, the version
// in CodeAccessPermission does this:
//    1. If target is not null, a NotSupportedException is thrown.
//    2. If target is null, then Copy is called and the new object is returned.
public override IPermission Union(IPermission target)
{
    // If 'target' is null, then return a copy of 'this'.
    if (target == null) return Copy();

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

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

    // Return a new object with the calculated, unioned permission value.
    return Clone(false, (SoundPermissionState)
        Math.Max((Int32)m_flags, (Int32)soundPerm.m_flags));
}
' Return a new object that contains the union of 'this' and 'target'.
' Note: You do not have to implement this method. If you do not, the version
' in CodeAccessPermission does this:
'    1. If target is not null, a NotSupportedException is thrown.
'    2. If target is null, then Copy is called and the new object is returned.
Public Overrides Function Union(ByVal target As IPermission) As IPermission
    ' If 'target' is null, then return a copy of 'this'.
    If target Is Nothing Then
        Return Copy()
    End If
    ' Both objects must be the same type.
    Dim soundPerm As SoundPermission = VerifyTypeMatch(target)

    ' If 'this' or 'target' are unrestricted, return a new unrestricted permission.
    If m_specifiedAsUnrestricted OrElse soundPerm.m_specifiedAsUnrestricted Then
        Return Clone(True, SoundPermissionState.PlayAnySound)
    End If
    ' Return a new object with the calculated, unioned permission value.
    Return Clone(False, CType(Math.Max(CType(m_flags, Int32), CType(soundPerm.m_flags, Int32)), SoundPermissionState))

End Function 'Union

Comentarios

El resultado de una llamada a Union es un permiso que representa todas las operaciones representadas por el permiso actual y el permiso especificado. Cualquier demanda que pase cualquiera de los permisos pasa su unión.

Las siguientes instrucciones deben ser true para todas las implementaciones del Union método . X y Y representan IPermission objetos que no nullson .

  • X. Union(X) devuelve un objeto que tiene el mismo valor Xque .

  • X. Union(Y) devuelve un objeto que tiene el mismo valor que el objeto devuelto por Y. Union(X).

  • X. Union(null) devuelve un objeto que tiene el mismo valor Xque .

Se aplica a