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

注解

两个权限的交集是一个权限,用于描述它们共同描述的操作集。 只有传递两个原始权限的要求才会传递交集。

两个相同的强名称标识权限的交集是相同的权限。 两个不同 (不是通配符) 表达式的交集是空权限。 通配符表达式和匹配的强名称的交集是强名称。 匹配的两个通配符表达式的交集较长,更具体。

适用于