FileDialogPermission.Copy 方法

创建并返回当前权限的相同副本。

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

语法

声明
Public Overrides Function Copy As IPermission
用法
Dim instance As FileDialogPermission
Dim returnValue As IPermission

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

返回值

当前权限的副本。

备注

权限副本对资源具有与原始权限相同的访问权限。

示例

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

Private Function CopyDemo() As Boolean 
    
    Dim returnValue As Boolean = True
    
    fileDialogPerm2 = CType(fileDialogPerm1.Copy(), FileDialogPermission)
    Console.WriteLine("Result of copy = " + fileDialogPerm2.ToString())
    
    Return returnValue

End Function 'CopyDemo
private bool CopyDemo()
{

    bool returnValue = true;

    fileDialogPerm2 = (FileDialogPermission)fileDialogPerm1.Copy();
    Console.WriteLine("Result of copy = " + fileDialogPerm2.ToString());

    return returnValue;
}
bool CopyDemo()
{
    bool returnValue = true;
    FileDialogPermission^ fileDialogIdPerm1 = gcnew FileDialogPermission(FileDialogPermissionAccess::Open );
    FileDialogPermission^ fileDialogIdPerm2 = gcnew FileDialogPermission( FileDialogPermissionAccess::OpenSave );

    FileDialogPermission^ fileDialogIdPerm3 = gcnew FileDialogPermission(PermissionState::None);

    fileDialogIdPerm2 = dynamic_cast<FileDialogPermission^>(fileDialogIdPerm1->Copy());
    Console::WriteLine( "Result of copy = {0}", fileDialogIdPerm2 );

    return returnValue;
}

// Copy creates and returns an identical copy of the current permission.
private boolean CopyDemo() 
{
    boolean returnValue = true;
    FileDialogPermissionAccess fileDialog1[] = 
        new FileDialogPermissionAccess[1];
    FileDialogPermission fileDialogIdPerm1[] = 
        new FileDialogPermission[1];
    FileDialogPermission fileDialogIdPerm2[] = 
        new FileDialogPermission[1];
    FileDialogGenerator fileDialogGen1 =  
        new FileDialogGenerator();
    FileDialogGenerator fileDialogGen2 =  
        new FileDialogGenerator();

    fileDialogGen1.ResetIndex();
    while(fileDialogGen1.CreateFileDialog(fileDialogIdPerm1, 
        fileDialog1)) {
        if ( fileDialogIdPerm1[0] == null  ) {
            continue ;
        }
        fileDialogGen2.ResetIndex();
        Console.WriteLine("************************" 
            + "********************************\n");
        try {
            fileDialogIdPerm2[0] =(
                (FileDialogPermission)(fileDialogIdPerm1[0].Copy()));
            Console.WriteLine(("Result of copy = " 
                + fileDialogIdPerm2[0].ToString()));
        } 
        catch(System.Exception  e) {
            Console.WriteLine(("Copy failed :" 
                + fileDialogIdPerm1[0].ToString() + e));
            continue ;
        }
    }
    return returnValue ;
} //CopyDemo   

平台

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 命名空间