Uredi

Deli z drugimi prek


ReflectionPermission.Union(IPermission) Method

Definition

Creates a permission that is the union of the current permission and the specified permission.

public:
 override System::Security::IPermission ^ Union(System::Security::IPermission ^ other);
public override System.Security.IPermission Union (System.Security.IPermission other);
override this.Union : System.Security.IPermission -> System.Security.IPermission
Public Overrides Function Union (other As IPermission) As IPermission

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.

Exceptions

The other parameter is not null and is not of the same type as the current permission.

Examples

The following code example shows the behavior of the Union method. This example is part of a larger example provided for the ReflectionPermission class.

Note

The code example is intended to show the behavior of the method, not to demonstrate its use. In general, the methods of permission classes are used by the security infrastructure; they are not typically used in applications.

private static void UnionDemo()
{
    ReflectionPermission memberAccessPerm = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess);
    ReflectionPermission restrictedMemberAccessPerm = new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess);
    ReflectionPermission reflectionPerm3 = (ReflectionPermission)memberAccessPerm.Union(restrictedMemberAccessPerm);
    if (reflectionPerm3 == null)
    {
        Console.WriteLine("The union of " + memberAccessPerm.Flags + " and " +
            restrictedMemberAccessPerm.Flags + " is null.");
    }
    else
    {
        Console.WriteLine("The union of " + memberAccessPerm.Flags + " and " +
            restrictedMemberAccessPerm.Flags + " = " +
            ((ReflectionPermission)reflectionPerm3).Flags.ToString());
    }
}
Private Shared Sub UnionDemo()
    Dim memberAccessPerm As New ReflectionPermission(ReflectionPermissionFlag.MemberAccess)
    Dim restrictedMemberAccessPerm As New ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess)
    Dim reflectionPerm3 As ReflectionPermission = _
            CType(memberAccessPerm.Union(restrictedMemberAccessPerm), ReflectionPermission)
    If reflectionPerm3 Is Nothing Then
        Console.WriteLine("The union of " + memberAccessPerm.Flags.ToString() + " and " + _
        restrictedMemberAccessPerm.Flags.ToString() + " is null.")
    Else
        Console.WriteLine("The union of " + memberAccessPerm.Flags.ToString() + _
        " and " + restrictedMemberAccessPerm.Flags.ToString() + " = " + _
        CType(reflectionPerm3, ReflectionPermission).Flags.ToString())
    End If

End Sub

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.

Applies to