This documentation is archived and is not being maintained.

RegistryPermission.Intersect Method

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

[Visual Basic]
Overrides Public Function Intersect( _
   ByVal target As IPermission _
) As IPermission Implements IPermission.Intersect
[C#]
public override IPermission Intersect(
 IPermission target
);
[C++]
public: IPermission* Intersect(
 IPermission* target
);
[JScript]
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.

Implements

IPermission.Intersect

Exceptions

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

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.

Example

[Visual Basic] 
' 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 reg1, reg2 As String
    Dim regPerm1, regPerm2, regIdPerm3 As RegistryPermission

    Dim regGen1 As New regGenerator()
    Dim regGen2 As New regGenerator()

    regGen1.ResetIndex()
    While regGen1.CreateReg(regPerm1, reg1, RegistryPermissionAccess.Read)
        If reg1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("**********************************************************" & ControlChars.Lf)
        regGen2.ResetIndex()

        While regGen2.CreateReg(regPerm2, reg2, RegistryPermissionAccess.Read)
            If regPerm2 Is Nothing Then
                GoTo ContinueWhile2
            End If
            Dim firstPermission As String = IIf(reg1 = "" Or reg1 Is Nothing, "null", reg1)
            Dim secondPermission As String = IIf(reg2 = "" Or reg2 Is Nothing, "null", reg2)
            Try

                regIdPerm3 = CType(regPerm1.Intersect(regPerm2), RegistryPermission)
                If Not (regIdPerm3 Is Nothing) AndAlso Not (regIdPerm3.GetPathList(RegistryPermissionAccess.Read) Is Nothing) Then

                    Console.WriteLine(("The intersection of " & firstPermission & "  and " & ControlChars.Lf & ControlChars.Tab & secondPermission & " = " & ControlChars.Lf & ControlChars.Tab & CType(regIdPerm3, RegistryPermission).GetPathList(RegistryPermissionAccess.Read).ToString()))
                Else
                    Console.WriteLine(("The intersection of " & firstPermission & "  and " & ControlChars.Lf & ControlChars.Tab & secondPermission & " is null. "))
                End If
            Catch e As Exception
                Console.WriteLine(("An exception was thrown for intersection : " & e.ToString()))
                returnValue = False
            End Try
ContinueWhile2:
        End While
ContinueWhile1:
    End While

    Return returnValue
End Function 'IntersectDemo


[C#] 
// 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;

    string reg1,reg2;
    RegistryPermission regPerm1,regPerm2,regIdPerm3;

    RegGenerator regGen1 = new RegGenerator();
    RegGenerator regGen2 = new RegGenerator();

    regGen1.ResetIndex();
    while(regGen1.CreateReg(out regPerm1, out reg1, RegistryPermissionAccess.Read)) 
    {
        if(reg1 == null) continue;
        Console.WriteLine("**********************************************************\n");
        regGen2.ResetIndex();

        while(regGen2.CreateReg(out regPerm2, out reg2, RegistryPermissionAccess.Read)) 
        {
            if(regPerm2 == null) continue;
            string firstPermission = reg1 == "" | reg1 == null ? "null" : reg1 ;
            string secondPermission = reg2 == "" | reg2 == null ? "null" : reg2;
            try
            {
        
                regIdPerm3 = (RegistryPermission)regPerm1.Intersect(regPerm2);
                if (regIdPerm3 != null && regIdPerm3.GetPathList(RegistryPermissionAccess.Read) != null)
                {

                    Console.WriteLine("The intersection of " + firstPermission 
                        + "  and \n\t"  + secondPermission + " = \n\t" 
                        + ((RegistryPermission)regIdPerm3).GetPathList(RegistryPermissionAccess.Read).ToString());
                }
                else
                {
                    Console.WriteLine("The intersection of " + firstPermission 
                        + "  and \n\t"  + secondPermission + " is null. ");
                }
            }
            catch(Exception e) 
            {
                Console.WriteLine("An exception was thrown for intersection : "  + e);
                returnValue=false;
            }
        }
    }

    return returnValue;

}

[C++] 
// Intersect creates and returns a new permission that is the intersection of the 
// current permission and the permission specified.
bool IntersectDemo()
{

    bool returnValue = true;

    String* reg1;
    String* reg2;
    RegistryPermission* regPerm1;
    RegistryPermission* regPerm2;
    RegistryPermission* regIdPerm3;

    RegGenerator* regGen1 = new RegGenerator();
    RegGenerator* regGen2 = new RegGenerator();

    regGen1->ResetIndex();
    while(regGen1->CreateReg(&regPerm1, &reg1, RegistryPermissionAccess::Read)) 
    {
        if(reg1 == 0) continue;
        Console::WriteLine(S"**********************************************************\n");
        regGen2->ResetIndex();

        while(regGen2->CreateReg(&regPerm2, &reg2, RegistryPermissionAccess::Read)) 
        {
            if(regPerm2 == 0) continue;
            String* firstPermission = reg1->Equals(S"") || reg1 == 0 ? S"null" : reg1 ;
            String* secondPermission = reg2->Equals(S"") || reg2 == 0 ? S"null" : reg2;
            try
            {

                regIdPerm3 = dynamic_cast<RegistryPermission*>(regPerm1->Intersect(regPerm2));
                if (regIdPerm3 != 0 && regIdPerm3->GetPathList(RegistryPermissionAccess::Read) != 0)
                {

                    Console::WriteLine(S"The intersection of {0}  and \n\t{1} = \n\t{2}", firstPermission, secondPermission, (dynamic_cast<RegistryPermission*>(regIdPerm3))->GetPathList(RegistryPermissionAccess::Read));
                }
                else
                {
                    Console::WriteLine(S"The intersection of {0}  and \n\t{1} is null. ", firstPermission, secondPermission);
                }
            }
            catch(Exception* e) 
            {
                Console::WriteLine(S"An exception was thrown for intersection : {0}", e);
                returnValue=false;
            }
        }
    }

    return returnValue;

}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

RegistryPermission Class | RegistryPermission Members | System.Security.Permissions Namespace

Show: