Udostępnij przez


StrongNameIdentityPermission.Intersect(IPermission) Metoda

Definicja

Tworzy i zwraca uprawnienie, które jest skrzyżowaniem bieżącego uprawnienia i określonego uprawnienia.

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

Parametry

target
IPermission

Uprawnienie do przecinania się z bieżącym uprawnieniem. Musi być tego samego typu co bieżące uprawnienie.

Zwraca

Nowe uprawnienie, które reprezentuje przecięcie bieżącego uprawnienia i określonego uprawnienia, lub null jeśli skrzyżowanie jest puste.

Wyjątki

Parametr target nie null jest i nie jest tego samego typu co bieżące uprawnienie.

Przykłady

Poniższy przykład kodu przedstawia wyniki użycia Intersect metody, a nie sposób użycia metody . Ten przykład jest częścią większego przykładu udostępnionego StrongNameIdentityPermission dla klasy . Najlepszym zastosowaniem w tym przykładzie jest skompilowanie i wykonanie całego przykładu oraz wyświetlenie jego danych wyjściowych.

Uwaga

Przykładowy kod jest przeznaczony do pokazania zachowania metody, a nie do zademonstrowania jej użycia. Ogólnie rzecz biorąc, metody klas uprawnień są używane przez infrastrukturę zabezpieczeń; nie są one zwykle używane w aplikacjach.

// 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

Uwagi

Przecięcie dwóch uprawnień to uprawnienie, które opisuje zestaw operacji, które opisują wspólne. Tylko żądanie, które przekazuje oba oryginalne uprawnienia, przejdą skrzyżowanie.

Przecięcie dwóch identycznych uprawnień tożsamości o silnej nazwie jest tym samym uprawnieniem. Przecięcie dwóch różnych wyrażeń (nie symboli wieloznacznych) jest pustym uprawnieniem. Przecięcie wyrażenia wieloznacznych i pasującej silnej nazwy jest silną nazwą. Przecięcie dwóch wyrażeń wieloznacznych, które są zgodne, jest dłuższe, bardziej szczegółowe dla dwóch wyrażeń.

Dotyczy