FileDialogPermission.Union 方法

创建一个权限,该权限是当前权限与指定权限的并集。

**命名空间:**System.Security.Permissions
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Overrides Function Union ( _
    target As IPermission _
) As IPermission
用法
Dim instance As FileDialogPermission
Dim target As IPermission
Dim returnValue As IPermission

returnValue = instance.Union(target)
public override IPermission Union (
    IPermission target
)
public:
virtual IPermission^ Union (
    IPermission^ target
) override
public IPermission Union (
    IPermission target
)
public override function Union (
    target : IPermission
) : IPermission

参数

  • target
    将与当前权限合并的权限。它必须与当前权限属于同一类型。

返回值

一个新权限,它表示当前权限与指定权限的并集。

异常

异常类型 条件

ArgumentException

target 参数不是 空引用(在 Visual Basic 中为 Nothing),而且与当前权限不是同一类型。

备注

调用 Union 得到一个权限,该权限表示由当前权限和指定权限表示的所有操作。通过任何一个权限的任何请求都会通过这些权限的并集。

示例

下面的代码示例旨在演示 Union 方法的行为,而不演示其用法。一般情况下,权限类的方法由安全性基础结构使用,而不在应用程序中使用。但是,下面的代码示例将演示在从您的代码执行该方法时,该方法将如何执行。有关完整的代码示例,请参见 FileDialogPermission 类。

Private Function UnionDemo() As Boolean 
    Dim returnValue As Boolean = True
    
    fileDialogPerm3 = CType(fileDialogPerm1.Union(fileDialogPerm2), FileDialogPermission)
    
    If fileDialogPerm3 Is Nothing Then
        Console.WriteLine("The union of " + fileDialogPerm1.Access.ToString() + _
        " and " + fileDialogPerm2.Access.ToString() + " is null.")
    Else
        Console.WriteLine("The union of " + fileDialogPerm1.Access.ToString() + _
        " and " + fileDialogPerm2.Access.ToString() + " = " + _
        CType(fileDialogPerm3, FileDialogPermission).Access.ToString())
    End If
    
    Return returnValue

End Function 'UnionDemo
 
private bool UnionDemo()
{
    bool returnValue = true;

            fileDialogPerm3 = (FileDialogPermission)fileDialogPerm1.Union(fileDialogPerm2);

            if (fileDialogPerm3 == null)
            {
                Console.WriteLine("The union of " + fileDialogPerm1.Access + 
                    " and " + fileDialogPerm2.Access + " is null.");
            }
            else
            {
                Console.WriteLine("The union of " + fileDialogPerm1.Access + " and " +
                    fileDialogPerm2.Access + " = " +
                    ((FileDialogPermission)fileDialogPerm3).Access.ToString());
            }

    return returnValue;

}
bool UnionDemo()
{
    bool returnValue = true;
    FileDialogPermission^ fileDialogIdPerm1 = gcnew FileDialogPermission(FileDialogPermissionAccess::Open );
    FileDialogPermission^ fileDialogIdPerm2 = gcnew FileDialogPermission( FileDialogPermissionAccess::OpenSave );
    FileDialogPermission^ fileDialogIdPerm3 = gcnew FileDialogPermission(PermissionState::None);
    fileDialogIdPerm3 = dynamic_cast<FileDialogPermission^>(fileDialogIdPerm1->Union( fileDialogIdPerm2 ));
    if ( fileDialogIdPerm3 == nullptr )
    {
        Console::WriteLine( "The union of {0} and {1} is null.", 
            fileDialogIdPerm1->Access, fileDialogIdPerm2->Access );
    }
    else
    {
        Console::WriteLine( "The union of {0} and {1} = {2}", 
            fileDialogIdPerm1->Access, fileDialogIdPerm2->Access, (dynamic_cast<FileDialogPermission^>(fileDialogIdPerm3))->Access );
    }
    return returnValue;
}

// Union creates a new permission that is the union of 
// the current permission and the
// specified permission.
private boolean UnionDemo() 
{
    boolean returnValue = true;
    FileDialogPermissionAccess fileDialog1[] = 
        new FileDialogPermissionAccess[1];
    FileDialogPermissionAccess fileDialog2[] = 
        new FileDialogPermissionAccess[1];
    FileDialogPermission fileDialogIdPerm1[] = 
        new FileDialogPermission[1];
    FileDialogPermission fileDialogIdPerm2[] = 
        new FileDialogPermission[1];
    IPermission fileDialogIdPerm3;
    FileDialogGenerator fileDialogGen1 =  
        new FileDialogGenerator();
    FileDialogGenerator fileDialogGen2 =  
        new FileDialogGenerator();
    fileDialogGen1.ResetIndex();
    while(fileDialogGen1.CreateFileDialog(fileDialogIdPerm1, 
        fileDialog1)) {
        if (fileDialogIdPerm1[0] == null) {
            continue ;
        }
        Console.WriteLine("************************" 
            + "**********************************\n");
        fileDialogGen2.ResetIndex();
        
        while(fileDialogGen2.CreateFileDialog(fileDialogIdPerm2, 
            fileDialog2)) {
            if (fileDialogIdPerm2[0] == null) {
                continue ;
            }
            fileDialogIdPerm3 =((FileDialogPermission)(
                fileDialogIdPerm1[0].Union(fileDialogIdPerm2[0])));
            fileDialogIdPerm3 = fileDialogIdPerm1[0].
                Union(fileDialogIdPerm2[0]);
            
            if (fileDialogIdPerm3 == null) {
                Console.WriteLine(("The union of " + fileDialog1[0] 
                    + " and " + fileDialog2[0] + " is null."));
            }
            else {
                Console.WriteLine(("The union of " 
                    + fileDialogIdPerm1[0].get_Access() + " and " 
                    + fileDialogIdPerm2[0].get_Access() + " = " 
                    + ((FileDialogPermission)(fileDialogIdPerm3)).
                    get_Access().ToString()));
            }
        }
    }
    return returnValue ;
} //UnionDemo

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

FileDialogPermission 类
FileDialogPermission 成员
System.Security.Permissions 命名空间