Export (0) Print
Expand All

FileIOPermission.Union Method

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

[Visual Basic]
Overrides Public Function Union( _
   ByVal other As IPermission _
) As IPermission Implements IPermission.Union
[C#]
public override IPermission Union(
 IPermission other
);
[C++]
public: IPermission* Union(
 IPermission* other
);
[JScript]
public override function Union(
   other : IPermission
) : IPermission;

Parameters

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

Return Value

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

Implements

IPermission.Union

Exceptions

Exception Type Condition
ArgumentException The other parameter is not a null reference (Nothing in Visual Basic) and is not of the same type as the current permission.

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.

Example

[Visual Basic] 
' Union creates a new permission that is the union of the current permission and the specified permission.
Private Function UnionDemo() As Boolean

    Dim returnValue As Boolean = True

    Dim fileIO1, fileIO2 As String
    Dim fileIOPerm1, fileIOPerm2 As FileIOPermission
    Dim fileIOPerm3 As IPermission

    Dim fileIOGen1 As New FileIOGenerator()
    Dim fileIOGen2 As New FileIOGenerator()

    fileIOGen1.ResetIndex()
    While fileIOGen1.CreateFilePath(fileIOPerm1, fileIO1, FileIOPermissionAccess.Read)
        If fileIO1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("**********************************************************" & ControlChars.Lf)
        fileIOGen2.ResetIndex()

        While fileIOGen2.CreateFilePath(fileIOPerm2, fileIO2, FileIOPermissionAccess.Read)

            Try
                If fileIOPerm2 Is Nothing Then
                    GoTo ContinueWhile2
                End If
                Dim firstPermission As String = IIf(fileIO1 = "" Or fileIO1 Is Nothing, "null", fileIO1)
                Dim secondPermission As String = IIf(fileIO2 = "" Or fileIO2 Is Nothing, "null", fileIO2)
                fileIOPerm3 = CType(fileIOPerm1.Union(fileIOPerm2), FileIOPermission)
                fileIOPerm3 = fileIOPerm1.Union(fileIOPerm2)

                If fileIOPerm3 Is Nothing Then
                    Console.WriteLine(("The union of " & firstPermission & "  and " & secondPermission & " is null."))
                Else
                    Console.WriteLine(("The union of " & firstPermission & "  and " & secondPermission & " = " & ControlChars.Lf & ControlChars.Tab & CType(fileIOPerm3, FileIOPermission).GetPathList(FileIOPermissionAccess.Read)(0)))
                End If
            Catch e As Exception
                Console.WriteLine(("An exception was thrown for union " & e.ToString()))
                returnValue = False
            End Try
ContinueWhile2:
        End While
ContinueWhile1:
    End While


    Return returnValue
End Function 'UnionDemo


[C#] 
// Union creates a new permission that is the union of the current permission and the specified permission.
    private bool UnionDemo()
    {

        bool returnValue = true;

        string fileIO1,fileIO2;
        FileIOPermission fileIOPerm1,fileIOPerm2;
        IPermission fileIOPerm3;

        FileIOGenerator fileIOGen1 = new FileIOGenerator();
        FileIOGenerator fileIOGen2 = new FileIOGenerator();

        fileIOGen1.ResetIndex();
        while(fileIOGen1.CreateFilePath(out fileIOPerm1, out fileIO1, FileIOPermissionAccess.Read)) 
        {
            if(fileIO1 == null) continue;
                
            Console.WriteLine("**********************************************************\n");
            fileIOGen2.ResetIndex();

            while(fileIOGen2.CreateFilePath(out fileIOPerm2, out fileIO2, FileIOPermissionAccess.Read)) 
            {

                try
                {
                    if(fileIOPerm2 == null) continue;

                    string firstPermission = fileIO1 == "" | fileIO1 == null ? "null" : fileIO1 ;
                    string secondPermission = fileIO2 == "" | fileIO2 == null ? "null" : fileIO2;
                    fileIOPerm3 = (FileIOPermission)fileIOPerm1.Union(fileIOPerm2);
                    fileIOPerm3 = fileIOPerm1.Union(fileIOPerm2);

                    if(fileIOPerm3 == null) 
                    {
                        Console.WriteLine("The union of " + firstPermission + "  and "  + secondPermission + " is null.");
                    }
                    else
                    {
                        Console.WriteLine("The union of " + firstPermission + "  and "  + secondPermission + 
                            " = \n\t" + ((FileIOPermission)fileIOPerm3).GetPathList(FileIOPermissionAccess.Read)[0]);
                    }
                }
                catch(Exception e) 
                {
                    Console.WriteLine("An exception was thrown for union " + e);
                    returnValue=false;
                }

            }
                
        }

        return returnValue;

    }

[C++] 
// Union creates a new permission that is the union of the current permission and the specified permission.
private:
bool UnionDemo()
{

    bool returnValue = true;

    String* fileIO1;
    String* fileIO2;

    FileIOPermission* fileIOPerm1;
    FileIOPermission* fileIOPerm2;

    IPermission* fileIOPerm3;

    FileIOGenerator* fileIOGen1 = new FileIOGenerator();
    FileIOGenerator* fileIOGen2 = new FileIOGenerator();

    fileIOGen1->ResetIndex();
    while(fileIOGen1->CreateFilePath(&fileIOPerm1, &fileIO1, FileIOPermissionAccess::Read)) 
    {
        if(fileIO1 == 0) continue;

        Console::WriteLine(S"**********************************************************\n");
        fileIOGen2->ResetIndex();

        while(fileIOGen2->CreateFilePath(&fileIOPerm2, &fileIO2, FileIOPermissionAccess::Read)) 
        {

            try
            {
                if(fileIOPerm2 == 0) continue;

                String* firstPermission = fileIO1->Equals(S"") | fileIO1->Equals((String*)0) ? S"null" : fileIO1 ;
                String* secondPermission = fileIO2->Equals(S"") | fileIO2->Equals((String*)0) ? S"null" : fileIO2;
                fileIOPerm3 = dynamic_cast<FileIOPermission*>(fileIOPerm1->Union(fileIOPerm2));
                fileIOPerm3 = fileIOPerm1->Union(fileIOPerm2);

                if(fileIOPerm3 == 0) 
                {
                    Console::WriteLine(S"The union of {0}  and {1} is null.", firstPermission, secondPermission);
                }
                else
                {
                    Console::WriteLine(S"The union of {0}  and {1} = \n\t{2}", firstPermission, secondPermission,
                        (dynamic_cast<FileIOPermission*>(fileIOPerm3))->GetPathList(FileIOPermissionAccess::Read)[0]);
                }
            }
            catch(Exception* e) 
            {
                Console::WriteLine(S"An exception was thrown for union {0}", e);
                returnValue=false;
            }

        }

    }

    return returnValue;

}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

FileIOPermission Class | FileIOPermission Members | System.Security.Permissions Namespace

Show:
© 2014 Microsoft