IPermission.Union(IPermission) Metodo

Definizione

Crea un'autorizzazione che rappresenta l'unione dell'autorizzazione corrente e di quella specificata.Creates a permission that is the union of the current permission and the specified permission.

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

Parametri

target
IPermission

Autorizzazione da combinare con quella corrente.A permission to combine with the current permission. Deve essere dello stesso tipo dell'autorizzazione corrente.It must be of the same type as the current permission.

Restituisce

Nuova autorizzazione che rappresenta l'unione dell'autorizzazione corrente e di quella specificata.A new permission that represents the union of the current permission and the specified permission.

Eccezioni

Il parametro target non è null e non è dello stesso tipo dell'autorizzazione corrente.The target parameter is not null and is not of the same type as the current permission.

Esempi

Nell'esempio di codice riportato di seguito Union viene illustrata l'implementazione del metodo.The following code example demonstrates implementing the Union method. Questo esempio di codice fa parte di un esempio più ampio fornito IPermission per la classe.This code example is part of a larger example provided for the IPermission class.

    // 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

Commenti

Il risultato di una chiamata a Union è un'autorizzazione che rappresenta tutte le operazioni rappresentate sia dall'autorizzazione corrente che dall'autorizzazione specificata.The result of a call to Union is a permission that represents all the operations represented by both the current permission and the specified permission. Qualsiasi richiesta che supera le autorizzazioni passa l'Unione.Any demand that passes either permission passes their union.

È necessario che le istruzioni seguenti siano vere per tutte le implementazioni del Union metodo.The following statements are required to be true for all implementations of the Union method. Xe Y nullrappresentano IPermission oggetti che non lo sono.X and Y represent IPermission objects that are not null.

  • X. Union (X) restituisce un oggetto con lo stesso valore di X.X.Union(X) returns an object that has the same value as X.

  • X. Union (Y) restituisce un oggetto con lo stesso valore dell'oggetto restituito da Y. Union (X).X.Union(Y) returns an object that has the same value as the object returned by Y.Union(X).

  • X. Union (null) restituisce un oggetto con lo stesso valore di X.X.Union(null) returns an object that has the same value as X.

Si applica a