This documentation is archived and is not being maintained.

FileIOPermission.IsSubsetOf Method

Determines whether the current permission is a subset of the specified permission.

[Visual Basic]
Overrides Public Function IsSubsetOf( _
   ByVal target As IPermission _
) As Boolean Implements IPermission.IsSubsetOf
[C#]
public override bool IsSubsetOf(
 IPermission target
);
[C++]
public: bool IsSubsetOf(
 IPermission* target
);
[JScript]
public override function IsSubsetOf(
   target : IPermission
) : Boolean;

Parameters

target
A permission that is to be tested for the subset relationship. This permission must be the same type as the current permission.

Return Value

true if the current permission is a subset of the specified permission; otherwise, false.

Implements

IPermission.IsSubsetOf

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 current permission is a subset of the specified permission if the current permission specifies a set of operations that is contained by the specified permission. For example, a permission that represents read access to C:\example.txt is a subset of a permission that represents read access to C:\. If this method returns true, the current permission represents no more access to the protected resource than does the specified permission.

Example

[Visual Basic] 
' IsSubsetOf determines whether the current permission is a subset of the specified permission.
' This method compares various FileIOPermission paths with FileIOPermissionAccess set to AllAccess.
Private Function IsSubsetOfDemo() As Boolean

    Dim returnValue As Boolean = True

    Dim fileIO1, fileIO2 As String
    Dim fileIOPerm1, fileIOPerm2 As FileIOPermission

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

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

        fileIOGen2.ResetIndex()

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

                    Console.WriteLine((firstPermission & " is a subset of " & secondPermission & ControlChars.Lf))
                Else
                    Console.WriteLine((firstPermission & " is not a subset of " & secondPermission & ControlChars.Lf))
                End If

            Catch e As Exception
                Console.WriteLine(IIf("An exception was thrown for subset :" & fileIO1 = "", "null", IIf(fileIO1 & ControlChars.Lf & fileIO2 = "", "null", fileIO2 & ControlChars.Lf & e.ToString())))
            End Try
ContinueWhile2:
        End While
ContinueWhile1:
    End While
    Return returnValue
End Function 'IsSubsetOfDemo


[C#] 
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
// This method compares various FileIOPermission paths with FileIOPermissionAccess set to AllAccess.
    private bool IsSubsetOfDemo()
    {

        bool returnValue = true;

        string fileIO1,fileIO2;
        FileIOPermission fileIOPerm1,fileIOPerm2;

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

        fileIOGen1.ResetIndex();
        while(fileIOGen1.CreateFilePath(out fileIOPerm1, out fileIO1, FileIOPermissionAccess.AllAccess)) 
        {
            if(fileIOPerm1 == null) continue;

            Console.WriteLine("**********************************************************\n");

            fileIOGen2.ResetIndex();

            while(fileIOGen2.CreateFilePath(out fileIOPerm2, out fileIO2, FileIOPermissionAccess.AllAccess)) 
            {
                string firstPermission = fileIO1 == "" | fileIO1 == null ? "null" : fileIO1 ;
                string secondPermission = fileIO2 == "" | fileIO2 == null ? "null" : fileIO2;
                if(fileIOPerm2 == null) continue;
                try
                {            
                    if (fileIOPerm1.IsSubsetOf(fileIOPerm2))
                    {
                            
                        Console.WriteLine(firstPermission +" is a subset of " + secondPermission + "\n");
                    }
                    else
                    {
                        Console.WriteLine(firstPermission  +" is not a subset of " + secondPermission + "\n");
                    }

                }
                catch(Exception e) 
                {
                    Console.WriteLine("An exception was thrown for subset :" + fileIO1 == "" ? "null" : fileIO1 + "\n" + 
                        fileIO2 == "" ? "null" : fileIO2 +"\n" + e);
                }
            }
        }
        return returnValue;
    }

[C++] 
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
// This method compares various FileIOPermission paths with FileIOPermissionAccess set to AllAccess.
private:
bool IsSubsetOfDemo()
{

    bool returnValue = true;

    String* fileIO1;
    String* fileIO2;

    FileIOPermission* fileIOPerm1;
    FileIOPermission* fileIOPerm2;


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

    fileIOGen1->ResetIndex();
    while(fileIOGen1->CreateFilePath(&fileIOPerm1, &fileIO1, FileIOPermissionAccess::AllAccess)) 
    {
        if(fileIOPerm1 == 0) continue;

        Console::WriteLine(S"**********************************************************\n");

        fileIOGen2->ResetIndex();

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

                    Console::WriteLine(S"{0} is a subset of {1}\n", firstPermission, secondPermission);
                }
                else
                {
                    Console::WriteLine(S"{0} is not a subset of {1}\n", firstPermission, secondPermission);
                }

            }
            catch(Exception* e) 
            {
                Console::WriteLine(S"An exception was thrown for subset :{0}\n{1}\n{2}",
                    (fileIO1->Equals(S"")?S"null":fileIO1), (fileIO2->Equals(S"")?S"null":fileIO2), e);
            }
        }
    }
    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: