Upraviť

Zdieľať cez


StrongNameIdentityPermission.Intersect(IPermission) Method

Definition

Creates and returns a permission that is the intersection of the current permission and the specified permission.

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

Parameters

target
IPermission

A permission to intersect with the current permission. It must be of the same type as the current permission.

Returns

A new permission that represents the intersection of the current permission and the specified permission, or null if the intersection is empty.

Exceptions

The target parameter is not null and is not of the same type as the current permission.

Examples

The following code example shows the results of the use of the Intersect method, not how to use the method. This example is part of a larger example provided for the StrongNameIdentityPermission class. The best use for this example is to build and execute the entire example, and view its output.

Note

The code example is intended to show the behavior of the method, not to demonstrate its use. In general, the methods of permission classes are used by the security infrastructure; they are not typically used in applications.

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

Remarks

The intersection of two permissions is a permission that describes the set of operations they both describe in common. Only a demand that passes both original permissions will pass the intersection.

The intersection of two identical strong name identity permissions is the same permission. The intersection of two different (not wildcard) expressions is an empty permission. The intersection of a wildcard expression and a matching strong name is the strong name. The intersection of two wildcard expressions that match is the longer, more specific of the two expressions.

Applies to