StrongNameIdentityPermission.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 。 此示例是为 类提供的更大示例的一 StrongNameIdentityPermission 部分。 此示例的最佳用途是生成并执行整个示例,并查看其输出。

注意

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

//Copy creates and returns an identical copy of the current permission.
bool CopyDemo()
{
    bool returnValue = true;
    StrongNameIdentityPermission^ snIdPerm1;
    StrongNameIdentityPermission^ snIdPerm2;
    snIdPerm1 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", gcnew Version("1.0.0.0"));
    snIdPerm2 = gcnew StrongNameIdentityPermission(PermissionState::None);

    snIdPerm2 = dynamic_cast<StrongNameIdentityPermission^>(snIdPerm1->Copy());
    Console::WriteLine("Result of copy = " + snIdPerm2->ToString() + "\n");

    return returnValue;
}
//Copy creates and returns an identical copy of the current permission.
private bool CopyDemo()
{
    bool returnValue = true;

    StrongNameIdentityPermission snIdPerm1, snIdPerm2;

    snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", new Version("1.0.0.0"));
    snIdPerm2 = new StrongNameIdentityPermission(PermissionState.None);

    snIdPerm2 = (StrongNameIdentityPermission)snIdPerm1.Copy();
    Console.WriteLine("Result of copy = " + snIdPerm2.ToString() + "\n");

    return returnValue;
}
'Copy creates and returns an identical copy of the current permission.
Private Function CopyDemo() As Boolean 
    Dim returnValue As Boolean = True
    
    Dim snIdPerm1, snIdPerm2 As StrongNameIdentityPermission
    
    snIdPerm1 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", New Version("1.0.0.0"))
    snIdPerm2 = New StrongNameIdentityPermission(PermissionState.None)
    snIdPerm2 = CType(snIdPerm1.Copy(), StrongNameIdentityPermission)
    Console.WriteLine("Result of copy = " + snIdPerm2.ToString() + vbLf)
    
    Return returnValue

End Function 'CopyDemo

注解

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

适用于