CodeAccessPermission.Union(IPermission) Metodo

Definizione

Quando sottoposto a override in una classe derivata, crea un'autorizzazione che rappresenta l'unione dell'autorizzazione corrente e di quella specificata.

public:
 virtual System::Security::IPermission ^ Union(System::Security::IPermission ^ other);
public virtual System.Security.IPermission Union (System.Security.IPermission other);
abstract member Union : System.Security.IPermission -> System.Security.IPermission
override this.Union : System.Security.IPermission -> System.Security.IPermission
Public Overridable Function Union (other As IPermission) As IPermission

Parametri

other
IPermission

Autorizzazione da combinare con quella corrente. Deve essere dello stesso tipo dell'autorizzazione corrente.

Restituisce

Nuova autorizzazione che rappresenta l'unione dell'autorizzazione corrente e di quella specificata.

Implementazioni

Eccezioni

Il parametro other non è null. Questo metodo è supportato solo a questo livello quando viene passato null.

Esempio

Nell'esempio di codice seguente viene illustrato un override del Union metodo . Questo esempio di codice fa parte di un esempio più ampio fornito per la CodeAccessPermission classe .

public:
   virtual IPermission^ Union( IPermission^ target ) override
   {
#if ( debug ) 
      Console::WriteLine( "************* Entering Union *********************" );
#endif 

      if ( target == nullptr )
      {
         return this;
      }

#if ( debug ) 
      Console::WriteLine( "This is = {0}", ((NameIdPermission)this).Name );
      Console::WriteLine( "Target is {0}", ((NameIdPermission)target).m_Name );
#endif 

      if (  !VerifyType( target ) )
      {
         throw gcnew ArgumentException( String::Format( "Argument_WrongType", this->GetType()->FullName ) );
      }

      NameIdPermission^ operand = dynamic_cast<NameIdPermission^>(target);

      if ( operand->IsSubsetOf( this ) )
      {
         return this->Copy();
      }
      else if ( this->IsSubsetOf( operand ) )
      {
         return operand->Copy();
      }
      else
      {
         return nullptr;
      }
   }
        public override IPermission Union(IPermission target)
        {
#if(debug)
            Console.WriteLine ("************* Entering Union *********************");
#endif
            if (target == null)
            {
                return this;
            }
#if(debug)
            Console.WriteLine ("This is = " + (( NameIdPermission)this).Name);
            Console.WriteLine ("Target is " + (( NameIdPermission)target).m_Name);
#endif
            if (!VerifyType(target))
            {
                throw new ArgumentException (String.Format ("Argument_WrongType", this.GetType ().FullName));
            }

             NameIdPermission operand = ( NameIdPermission)target;

            if (operand.IsSubsetOf (this)) return this.Copy ();
            else if (this.IsSubsetOf (operand)) return operand.Copy ();
            else
                return null;
        }
        Public Overrides Function Union(ByVal target As IPermission) As IPermission
#If (Debug) Then

            Console.WriteLine("************* Entering Union *********************")
#End If
            If target Is Nothing Then
                Return Me
            End If
#If (Debug) Then
            Console.WriteLine(("This is = " + CType(Me, NameIdPermission).Name))
            Console.WriteLine(("Target is " + CType(target, NameIdPermission).m_name))
#End If
            If Not VerifyType(target) Then
                Throw New ArgumentException(String.Format("Argument_WrongType", Me.GetType().FullName))
            End If

            Dim operand As NameIdPermission = CType(target, NameIdPermission)

            If operand.IsSubsetOf(Me) Then
                Return Me.Copy()
            ElseIf Me.IsSubsetOf(operand) Then
                Return operand.Copy()
            Else
                Return Nothing
            End If
        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. Qualsiasi richiesta che supera l'autorizzazione supera l'unione.

Note per gli eredi

È necessario eseguire l'override di questo metodo in una classe derivata. È necessario restituire una copia dell'autorizzazione se il valore del other parametro è null.

Si applica a