CodeAccessPermission.Union(IPermission) Method

Definition

When overridden in a derived class, creates a permission that is the union of the current permission and the specified permission.

C#
public virtual System.Security.IPermission Union(System.Security.IPermission other);

Parameters

other
IPermission

A permission to combine with the current permission. It must be of the same type as the current permission.

Returns

A new permission that represents the union of the current permission and the specified permission.

Implements

Exceptions

The other parameter is not null. This method is only supported at this level when passed null.

Examples

The following code example shows an override of the Union method. This code example is part of a larger example provided for the CodeAccessPermission class.

C#
        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;
        }

Remarks

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. Any demand that passes either permission passes their union.

Notes to Inheritors

You must override this method in a derived class. You should return a copy of the permission if the value of the other parameter is null.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10