IsSubsetOf Method

PrincipalPermission.IsSubsetOf Method (IPermission)


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

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

public bool IsSubsetOf(
	IPermission target


Type: System.Security.IPermission

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

Return Value

Type: System.Boolean

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

Exception Condition

The target parameter is an object that is not of the same type as the current permission.

The current permission is a subset of the specified permission if all demands that succeed for the current permission also succeed for the specified permission.

Legacy Code Example

The following example defines instances of PrincipalPermission corresponding to three distinct users. Two additional instances are then created as groups of users. pp1 represents Bob and Louise, pp2 represents Bob, Louise, and Greg.

private static void DemonstrateReadWriteXMLSchemaWithStream()
    DataTable table = CreateTestTable("XmlDemo");
    PrintSchema(table, "Original table");

    // Write the schema to XML in a memory stream.
    System.IO.MemoryStream xmlStream = new System.IO.MemoryStream();

    // Rewind the memory stream.
    xmlStream.Position = 0;

    DataTable newTable = new DataTable();

    // Print out values in the table.
    PrintSchema(newTable, "New table");

private static DataTable CreateTestTable(string tableName)
    // Create a test DataTable with two columns and a few rows.
    DataTable table = new DataTable(tableName);
    DataColumn column = new DataColumn("id", typeof(System.Int32));
    column.AutoIncrement = true;

    column = new DataColumn("item", typeof(System.String));

    // Add ten rows.
    DataRow row;
    for (int i = 0; i <= 9; i++)
        row = table.NewRow();
        row["item"] = "item " + i;

    return table;

private static void PrintSchema(DataTable table, string label)
    // Display the schema of the supplied DataTable:
    foreach (DataColumn column in table.Columns)
        Console.WriteLine("\t{0}: {1}", column.ColumnName, 

With the preceding declarations, pp1.IsSubsetOf(pp2) returns true, and pp2.IsSubsetOf(pp1) returns false.

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft