UIPermission.Copy 方法

定义

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

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

返回

当前权限的副本。

示例

下面的代码示例演示 了 方法的行为 Copy 。 此示例是为 类提供的更大示例的 UIPermission 一部分。

注意

代码示例旨在显示方法的行为,而不是演示其用法。 通常,权限类的方法由安全基础结构使用;它们通常不用于应用程序。

//Copy creates and returns an identical copy of the current permission.
void CopyDemo()
{
    Console::WriteLine("\n*************************  Copy() Demo *************************\n");

    UIPermission ^ uiPerm1 = gcnew UIPermission(UIPermissionWindow::SafeTopLevelWindows);
    UIPermission ^ uiPerm2 = gcnew UIPermission(PermissionState::None);
    uiPerm2 = (UIPermission ^)uiPerm1->Copy();
    if (uiPerm2 != nullptr)
        Console::WriteLine("The copy succeeded:  " + uiPerm2->ToString());
}
//Copy creates and returns an identical copy of the current permission.
private static void CopyDemo()
{

    UIPermission uiPerm1 = new UIPermission(UIPermissionWindow.SafeTopLevelWindows);
    UIPermission uiPerm2 = new UIPermission(PermissionState.None);
    uiPerm2 = (UIPermission)uiPerm1.Copy();
    if (uiPerm2 != null)
    {
        Console.WriteLine("The copy succeeded:  " + uiPerm2.ToString() + " \n");
    }
}
'Copy creates and returns an identical copy of the current permission.
Private Shared Sub CopyDemo()

    Dim uiPerm1 As New UIPermission(UIPermissionWindow.SafeTopLevelWindows)
    Dim uiPerm2 As New UIPermission(PermissionState.None)
    uiPerm2 = CType(uiPerm1.Copy(), UIPermission)
    If Not (uiPerm2 Is Nothing) Then
        Console.WriteLine("The copy succeeded:  " + uiPerm2.ToString() + " " + vbLf)
    End If

End Sub

注解

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

适用于