共用方式為


StrongNameIdentityPermission.Union(IPermission) 方法

定義

建立目前權限與指定權限聯集的權限。

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

參數

target
IPermission

要與目前權限結合的權限, 必須與目前權限屬於相同的類型。

傳回

代表目前權限與指定權限聯集的新權限。

例外狀況

target 參數不是 null,而且與目前權限屬於不同的類型。

-或-

兩個權限不相等,且其中一個權限是另一個權限的子集。

範例

下列程式代碼範例顯示使用 Union 方法的結果,而不是如何使用 方法。 這個範例是提供給 類別之較大範例的 StrongNameIdentityPermission 一部分。 此範例的最佳用法是建置和執行整個範例,並檢視其輸出。

注意

程式代碼範例旨在顯示 方法的行為,而不是示範其用法。 一般而言,安全性基礎結構會使用許可權類別的方法;它們通常不會用於應用程式。

// Union creates a new permission that is the union of the current permission and the specified permission.
bool UnionDemo()
{
    bool returnValue = true;
    StrongNameIdentityPermission^ snIdPerm1;
    StrongNameIdentityPermission^ snIdPerm2;
    IPermission^ snIdPerm3;
    snIdPerm1 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", gcnew Version("1.0.0.0"));
    snIdPerm2 = gcnew StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile", gcnew Version("1.0.0.0"));
    snIdPerm3 = dynamic_cast<StrongNameIdentityPermission^>(snIdPerm1->Union( snIdPerm2 ));
    snIdPerm3 = snIdPerm1->Union( snIdPerm2 );

    try
    {
        Console::WriteLine("The union of MyCompany.MyDepartment.*" +
            "and MyCompany.MyDepartment.MyFile is " +
            (dynamic_cast<StrongNameIdentityPermission^>(snIdPerm3))->Name); 
    }
    catch (Exception^ e)
    {
        Console::WriteLine("An expected exception was thrown: " + e->Message);
    }


    return returnValue;
}
// Union creates a new permission that is the union of the current permission and the specified permission.
private bool UnionDemo()
{

    bool returnValue = true;

    StrongNameIdentityPermission snIdPerm1, snIdPerm2;
    IPermission snIdPerm3;

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

    snIdPerm3 = (StrongNameIdentityPermission)snIdPerm1.Union(snIdPerm2);

    try
    {
        Console.WriteLine("The union of MyCompany.MyDepartment.*" +
        "and MyCompany.MyDepartment.MyFile is " +
        ((StrongNameIdentityPermission)snIdPerm3).Name.ToString());
    }
    catch (Exception e)
    {
        Console.WriteLine("An expected exception was thrown: " + e.Message);
    }

    return returnValue;
}
' Union creates a new permission that is the union of the current permission and the specified permission.
Private Function UnionDemo() As Boolean 
    
    Dim returnValue As Boolean = True
    
    Dim snIdPerm1, snIdPerm2 As StrongNameIdentityPermission
    Dim snIdPerm3 As IPermission
    
    snIdPerm1 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", New Version("1.0.0.0"))
    snIdPerm2 = New StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile", New Version("1.0.0.0"))
    
    snIdPerm3 = CType(snIdPerm1.Union(snIdPerm2), StrongNameIdentityPermission)
    
    Try
        Console.WriteLine("The union of MyCompany.MyDepartment.*" + "and MyCompany.MyDepartment.MyFile is " + CType(snIdPerm3, StrongNameIdentityPermission).Name.ToString())
    Catch e As Exception
        Console.WriteLine("An expected exception was thrown: " + e.Message)
    End Try
    
    
    Return returnValue

End Function 'UnionDemo

備註

呼叫 Union 的結果是許可權,代表目前許可權和指定許可權所代表的所有作業。 任何傳遞許可權的要求都會通過其等位。

許可權的聯集,而且 null 是不是 null的許可權。 許可權和該許可權子集的聯集是包含另一個許可權的許可權。 任何其他組合都會導致 ArgumentException 擲回例外狀況。

適用於