共用方式為


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

備註

許可權的複本代表與原始許可權相同的資源存取權。

適用於