共用方式為


StrongNameIdentityPermission.Intersect(IPermission) 方法

定義

建立並傳回目前權限與指定權限交集的權限。

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

參數

target
IPermission

要與目前權限產生交集的權限。 必須與目前權限屬於相同的類型。

傳回

代表目前權限與指定權限交集的新權限;如果交集是空的,則為 null

例外狀況

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

範例

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

注意

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

// Intersect creates and returns a new permission that is the intersection of the current
// permission and the permission specified.
bool IntersectDemo()
{
    bool returnValue = true;
    StrongNameIdentityPermission^ snIdPerm1;
    StrongNameIdentityPermission^ snIdPerm2;
    StrongNameIdentityPermission^ 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"));

    try
    {

        snIdPerm3 = dynamic_cast<StrongNameIdentityPermission^>(snIdPerm1->Intersect(snIdPerm2));

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

    return returnValue;

}
// Intersect creates and returns a new permission that is the intersection of the current
// permission and the permission specified.
private bool IntersectDemo()
{

    bool returnValue = true;

    StrongNameIdentityPermission snIdPerm1, snIdPerm2, 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"));

    try
    {

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

        Console.WriteLine("The intersection of MyCompany.MyDepartment.*"
        + "MyCompany.MyDepartment.MyFile is "
        + ((StrongNameIdentityPermission)snIdPerm3).Name.ToString());
    }
    catch (Exception e)
    {
        Console.WriteLine("An exception was thrown: " + e);
        returnValue = false;
    }

    return returnValue;
}
' Intersect creates and returns a new permission that is the intersection of the current
' permission and the permission specified.
Private Function IntersectDemo() As Boolean 
    
    Dim returnValue As Boolean = True
    
    Dim snIdPerm1, snIdPerm2, snIdPerm3 As StrongNameIdentityPermission
    
    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"))
    
    Try
        
        snIdPerm3 = CType(snIdPerm1.Intersect(snIdPerm2), StrongNameIdentityPermission)
        
        Console.WriteLine("The intersection of MyCompany.MyDepartment.*" + "MyCompany.MyDepartment.MyFile is " + CType(snIdPerm3, StrongNameIdentityPermission).Name.ToString())
    
    Catch e As Exception
        Console.WriteLine("An exception was thrown: " + e.ToString())
        returnValue = False
    End Try
    
    Return returnValue

End Function 'IntersectDemo

備註

兩個許可權的交集是描述兩者共同描述之作業集的許可權。 只有傳遞兩個原始許可權的要求才會通過交集。

兩個相同強名稱識別許可權的交集是相同的許可權。 兩個不同 (非通配符) 表達式的交集是空許可權。 通配符表達式和相符強名稱的交集是強名稱。 符合的兩個通配符表達式交集是兩個表達式的較長時間,更具體。

適用於