This documentation is archived and is not being maintained.

FileDialogPermission.Union Method

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

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

Parameters

target
A permission to combine with the current permission. It must be of 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 target 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 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 fileDialog1, fileDialog2 As FileDialogPermissionAccess
    Dim fileDialogIdPerm1, fileDialogIdPerm2 As FileDialogPermission
    Dim fileDialogIdPerm3 As IPermission
    Dim fileDialogGen1 As New FileDialogGenerator()
    Dim fileDialogGen2 As New FileDialogGenerator()
    fileDialogGen1.ResetIndex()
    While fileDialogGen1.CreateFileDialog(fileDialogIdPerm1, fileDialog1)
        If fileDialogIdPerm1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("**********************************************************" & ControlChars.Lf)
        fileDialogGen2.ResetIndex()

        While fileDialogGen2.CreateFileDialog(fileDialogIdPerm2, fileDialog2)
            If fileDialogIdPerm2 Is Nothing Then
                GoTo ContinueWhile2
            End If
            fileDialogIdPerm3 = CType(fileDialogIdPerm1.Union(fileDialogIdPerm2), FileDialogPermission)
            fileDialogIdPerm3 = fileDialogIdPerm1.Union(fileDialogIdPerm2)

            If fileDialogIdPerm3 Is Nothing Then
                Console.WriteLine(("The union of " & fileDialog1.ToString() & " and " & fileDialog2.ToString() & " is null."))
            Else
                Console.WriteLine(("The union of " & fileDialogIdPerm1.Access.ToString() & " and " & fileDialogIdPerm2.Access.ToString() & " = " & CType(fileDialogIdPerm3, FileDialogPermission).Access.ToString()))
            End If
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;
        FileDialogPermissionAccess fileDialog1,fileDialog2;
        FileDialogPermission fileDialogIdPerm1,fileDialogIdPerm2;
        IPermission fileDialogIdPerm3;
        FileDialogGenerator fileDialogGen1 = new FileDialogGenerator();
        FileDialogGenerator fileDialogGen2 = new FileDialogGenerator();
        fileDialogGen1.ResetIndex();
        while(fileDialogGen1.CreateFileDialog(out fileDialogIdPerm1, out fileDialog1)) 
        {
            if(fileDialogIdPerm1 == null) continue;
            Console.WriteLine("**********************************************************\n");
            fileDialogGen2.ResetIndex();

            while(fileDialogGen2.CreateFileDialog(out fileDialogIdPerm2, out fileDialog2)) 
            {
                if(fileDialogIdPerm2 == null) continue;
                fileDialogIdPerm3 = (FileDialogPermission)fileDialogIdPerm1.Union(fileDialogIdPerm2);
                fileDialogIdPerm3 = fileDialogIdPerm1.Union(fileDialogIdPerm2);

                if(fileDialogIdPerm3 == null)  
                {
                    Console.WriteLine("The union of " +  fileDialog1 + " and " + fileDialog2 + " is null." );
                }
                else
                {
                    Console.WriteLine("The union of " + fileDialogIdPerm1.Access + " and " + 
                        fileDialogIdPerm2.Access + " = " + 
                        ((FileDialogPermission)fileDialogIdPerm3).Access.ToString());
                }

            }
        }

        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;
   FileDialogPermissionAccess fileDialog1,fileDialog2;
   FileDialogPermission* fileDialogIdPerm1;
   FileDialogPermission* fileDialogIdPerm2;

   IPermission* fileDialogIdPerm3;
   FileDialogGenerator* fileDialogGen1 = new FileDialogGenerator();
   FileDialogGenerator* fileDialogGen2 = new FileDialogGenerator();
   fileDialogGen1->ResetIndex();
   while(fileDialogGen1->CreateFileDialog(&fileDialogIdPerm1, &fileDialog1)) 
   {
      if(fileDialogIdPerm1 == 0) continue;
      Console::WriteLine(S"**********************************************************\n");
      fileDialogGen2->ResetIndex();

      while(fileDialogGen2->CreateFileDialog(&fileDialogIdPerm2, &fileDialog2)) 
      {
         if(fileDialogIdPerm2 == 0) continue;
         fileDialogIdPerm3 = dynamic_cast<FileDialogPermission*>(fileDialogIdPerm1->Union(fileDialogIdPerm2));
         fileDialogIdPerm3 = fileDialogIdPerm1->Union(fileDialogIdPerm2);

         if(fileDialogIdPerm3 == 0)  
         {
            Console::WriteLine(S"The union of {0} and {1} is null.", __box(fileDialog1), __box(fileDialog2));
         }
         else
         {
            Console::WriteLine(S"The union of {0} and {1} = {2}", __box(fileDialogIdPerm1->Access), __box(fileDialogIdPerm2->Access), __box((dynamic_cast<FileDialogPermission*>(fileDialogIdPerm3))->Access));
         }

      }
   }

   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

See Also

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

Show: