This documentation is archived and is not being maintained.

FileIOPermission.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 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 fileIO1, fileIO2 As String
    Dim fileIOPerm1, fileIOPerm2, fileIOPerm3 As FileIOPermission

    Dim fileIOGen1 As New FileIOGenerator()
    Dim fileIOGen2 As New FileIOGenerator()

    fileIOGen1.ResetIndex()
    While fileIOGen1.CreateFilePath(fileIOPerm1, fileIO1, FileIOPermissionAccess.Read)
        If fileIO1 Is Nothing Then
            GoTo ContinueWhile1
        End If
        Console.WriteLine("**********************************************************" & ControlChars.Lf)
        fileIOGen2.ResetIndex()

        While fileIOGen2.CreateFilePath(fileIOPerm2, fileIO2, FileIOPermissionAccess.Read)
            If fileIOPerm2 Is Nothing Then
                GoTo ContinueWhile2
            End If
            Dim firstPermission As String = IIf(fileIO1 = "" Or fileIO1 Is Nothing, "null", fileIO1)
            Dim secondPermission As String = IIf(fileIO2 = "" Or fileIO2 Is Nothing, "null", fileIO2)
            Try

                fileIOPerm3 = CType(fileIOPerm1.Intersect(fileIOPerm2), FileIOPermission)
                If Not (fileIOPerm3 Is Nothing) AndAlso Not (fileIOPerm3.GetPathList(FileIOPermissionAccess.Read) Is Nothing) Then

                    Console.WriteLine(("The intersection of " & firstPermission & "  and " & ControlChars.Lf & ControlChars.Tab & secondPermission & " = " & ControlChars.Lf & ControlChars.Tab & CType(fileIOPerm3, FileIOPermission).GetPathList(FileIOPermissionAccess.Read)(0)))
                Else
                    Console.WriteLine(("The intersection of " & firstPermission & "  and " & 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 fileIO1,fileIO2;
        FileIOPermission fileIOPerm1,fileIOPerm2,fileIOPerm3;

        FileIOGenerator fileIOGen1 = new FileIOGenerator();
        FileIOGenerator fileIOGen2 = new FileIOGenerator();

        fileIOGen1.ResetIndex();
        while(fileIOGen1.CreateFilePath(out fileIOPerm1, out fileIO1, FileIOPermissionAccess.Read)) 
        {
            if(fileIO1 == null) continue;
            Console.WriteLine("**********************************************************\n");
            fileIOGen2.ResetIndex();

            while(fileIOGen2.CreateFilePath(out fileIOPerm2, out fileIO2, FileIOPermissionAccess.Read)) 
            {
                if(fileIOPerm2 == null) continue;
                string firstPermission = fileIO1 == "" | fileIO1 == null ? "null" : fileIO1 ;
                string secondPermission = fileIO2 == "" | fileIO2 == null ? "null" : fileIO2;
                try
                {
            
                    fileIOPerm3 = (FileIOPermission)fileIOPerm1.Intersect(fileIOPerm2);
                    if (fileIOPerm3 != null && fileIOPerm3.GetPathList(FileIOPermissionAccess.Read) != null)
                    {

                        Console.WriteLine("The intersection of " + firstPermission + "  and \n\t"  + secondPermission + 
                            " = \n\t" + ((FileIOPermission)fileIOPerm3).GetPathList(FileIOPermissionAccess.Read)[0]);
                    }
                    else
                    {
                        Console.WriteLine("The intersection of " + firstPermission + "  and "  + 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.
private:
bool IntersectDemo()
{

    bool returnValue = true;

    String* fileIO1;
    String* fileIO2;

    FileIOPermission* fileIOPerm1;
    FileIOPermission* fileIOPerm2;
    FileIOPermission* fileIOPerm3;


    FileIOGenerator* fileIOGen1 = new FileIOGenerator();
    FileIOGenerator* fileIOGen2 = new FileIOGenerator();

    fileIOGen1->ResetIndex();
    while(fileIOGen1->CreateFilePath(&fileIOPerm1, &fileIO1, FileIOPermissionAccess::Read)) 
    {
        if(fileIO1 == 0) continue;
        Console::WriteLine(S"**********************************************************\n");
        fileIOGen2->ResetIndex();

        while(fileIOGen2->CreateFilePath(&fileIOPerm2, &fileIO2, FileIOPermissionAccess::Read)) 
        {
            if(fileIOPerm2 == 0) continue;
            String* firstPermission = fileIO1->Equals(S"") | fileIO1->Equals((String*)0) ? S"null" : fileIO1 ;
            String* secondPermission = fileIO2->Equals(S"") | fileIO2->Equals((String*)0) ? S"null" : fileIO2;
            try
            {

                fileIOPerm3 = dynamic_cast<FileIOPermission*>(fileIOPerm1->Intersect(fileIOPerm2));
                if (fileIOPerm3 != 0 && fileIOPerm3->GetPathList(FileIOPermissionAccess::Read) != 0)
                {

                    Console::WriteLine(S"The intersection of {0}  and \n\t{1} = \n\t{2}", firstPermission, secondPermission,
                        (dynamic_cast<FileIOPermission*>(fileIOPerm3))->GetPathList(FileIOPermissionAccess::Read)[0]);
                }
                else
                {
                    Console::WriteLine(S"The intersection of {0}  and {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, Common Language Infrastructure (CLI) Standard

See Also

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

Show: