Export (0) Print
Expand All

FileIOPermission.IsSubsetOf Method

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

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

public override bool IsSubsetOf (
	IPermission target
)
public boolean IsSubsetOf (
	IPermission target
)
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.

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 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.

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 fileIO1 ))
    {
        if(fileIO1 == "")
            fileIOPerm1 = new FileIOPermission(PermissionState.None);
        else
        fileIOPerm1 = new FileIOPermission(FileIOPermissionAccess.AllAccess, fileIO1);

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

        fileIOGen2.ResetIndex();

        while (fileIOGen2.CreateFilePath(out fileIO2))
        {
            if (fileIO2 == "")
                fileIOPerm2 = new FileIOPermission(PermissionState.None);
            else
                fileIOPerm2 = new FileIOPermission(FileIOPermissionAccess.AllAccess, fileIO2);
            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;
}

// 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 boolean IsSubsetOfDemo() 
{
    boolean returnValue = true;
    String fileIO1[] = new String[1] ;
    String fileIO2[] = new String[1] ;
    FileIOPermission fileIOPerm1[] = new FileIOPermission[1] ;
    FileIOPermission fileIOPerm2[] = new FileIOPermission[1] ;
    
    FileIOGenerator fileIOGen1 =  new FileIOGenerator();
    FileIOGenerator fileIOGen2 =  new FileIOGenerator();
    
    fileIOGen1.ResetIndex();
    while(fileIOGen1.CreateFilePath(fileIOPerm1, fileIO1, 
        FileIOPermissionAccess.AllAccess)) {
        if (fileIOPerm1[0] == null) {
            continue ;
        }         
        Console.WriteLine("***********************" 
            + "***********************************\n");
        fileIOGen2.ResetIndex();
        
        while(fileIOGen2.CreateFilePath(fileIOPerm2, fileIO2, 
            FileIOPermissionAccess.AllAccess)) {
            String firstPermission = (fileIO1[0].equals("") == 
                true | fileIO1[0] == null) ? "null" : fileIO1[0];
            String secondPermission = (fileIO2[0].equals("") == 
                true | fileIO2[0] == null) ? "null" : fileIO2[0];
            if (fileIOPerm2[0] == null) {
                continue ;
            }
            try {
                if (fileIOPerm1[0].IsSubsetOf(fileIOPerm2[0])) {
                    Console.WriteLine((firstPermission 
                        + " is a subset of " 
                        + secondPermission + "\n"));
                }
                else {
                    Console.WriteLine((firstPermission 
                        + " is not a subset of " 
                        + secondPermission + "\n"));
                }
            } 
            catch(System.Exception e) {
                Console.WriteLine(("An exception was thrown for subset :" 
                    + ((fileIO1[0].equals("") == true) ? 
                    "null" : (fileIO1[0] + "\n" 
                    + ((fileIO2[0].equals("") == true) ? 
                    "null" : fileIO2[0]) + "\n" + e))));
            }
        }
    }
    return returnValue ;
} //IsSubsetOfDemo   

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:
© 2014 Microsoft