Export (0) Print
Expand All

ReflectionPermission.Intersect Method

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

Namespace: System.Security.Permissions
Assembly: mscorlib (in mscorlib.dll)

public override IPermission Intersect (
	IPermission target
)
public IPermission Intersect (
	IPermission target
)
public override function Intersect (
	target : IPermission
) : IPermission

Parameters

target

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

Return Value

A new permission that represents the intersection of the current permission and the specified permission. This new permission is a null reference (Nothing in Visual Basic) if the intersection is empty.

Exception typeCondition

ArgumentException

The target parameter is not a null reference (Nothing in Visual Basic) and is not of the same type as the current permission.

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.

private bool IntersectDemo()
{
    bool returnValue = true;
    ReflectionPermissionFlag reflection1, reflection2;
    ReflectionPermission reflectionPerm1, reflectionPerm2, reflectionPerm3;
    ReflectionGenerator reflectionGen1 = new ReflectionGenerator();
    ReflectionGenerator reflectionGen2 = new ReflectionGenerator();
    reflectionGen1.ResetIndex();
    while (reflectionGen1.CreateReflection(out reflection1))
    {
        reflectionPerm1 = new ReflectionPermission(reflection1);
        Console.WriteLine("**********************************************************\n");
        reflectionGen2.ResetIndex();

        while (reflectionGen2.CreateReflection(out reflection2))
        {
            reflectionPerm2 = new ReflectionPermission(reflection2);

            reflectionPerm3 = (ReflectionPermission)reflectionPerm1.Intersect(reflectionPerm2);
            if (reflectionPerm3 != null)
            {
                Console.WriteLine("The intersection of " + reflection1 + " and " + reflection2 + " = " +
                    ((ReflectionPermission)reflectionPerm3).Flags.ToString());
            }
            else
            {
                Console.WriteLine("The intersection of " + reflection1 + " and " + reflection2 + " is null.");
            }
        }
    }

    return returnValue;
}

private boolean IntersectDemo() 
{
    boolean returnValue = true;
    ReflectionPermissionFlag reflection1[] = 
        new ReflectionPermissionFlag[1];
    ReflectionPermissionFlag reflection2[] = 
        new ReflectionPermissionFlag[1];
    ReflectionPermission reflectionPerm1[] = 
        new ReflectionPermission[1];
    ReflectionPermission reflectionPerm2[] = 
        new ReflectionPermission[1];
    ReflectionPermission reflectionPerm3;
    ReflectionGenerator reflectionGen1 =  
        new ReflectionGenerator();
    ReflectionGenerator reflectionGen2 =  
        new ReflectionGenerator();
    reflectionGen1.ResetIndex();
    while(reflectionGen1.CreateReflection(reflectionPerm1, reflection1)) {
        if (reflectionPerm1[0] == null) {
            continue ;
        }
        Console.WriteLine("***************************************" 
            + "*******************\n");
        reflectionGen2.ResetIndex();
        
        while(reflectionGen2.CreateReflection(reflectionPerm2, 
            reflection2)) {
            if (reflectionPerm2[0] == null) {
                continue ;
            }
            
            reflectionPerm3 =((ReflectionPermission)(
                reflectionPerm1[0].Intersect(reflectionPerm2[0])));
            if (reflectionPerm3  != null) {
                Console.WriteLine(("The intersection of " 
                    + reflection1[0] + " and " 
                    + reflection2[0] + " = " 
                    + ((ReflectionPermission)(reflectionPerm3)).
                    get_Flags().ToString()));
            }
            else {
                Console.WriteLine(("The intersection of " 
                    + reflection1[0] + " and " + reflection2[0] 
                    + " is null."));
            }
        }
    }
    return returnValue ;
} //IntersectDemo   

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft