PermissionSet.IsSubsetOf(PermissionSet) Method

Definition

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

C#
public bool IsSubsetOf(System.Security.PermissionSet? target);
C#
public virtual bool IsSubsetOf(System.Security.PermissionSet target);
C#
public bool IsSubsetOf(System.Security.PermissionSet target);

Parameters

target
PermissionSet

The permission set to test for the subset relationship. This must be either a PermissionSet or a NamedPermissionSet.

Returns

true if the current PermissionSet is a subset of the target parameter; otherwise, false.

Examples

The following code example shows the use of the IsSubsetOf method. This code example is part of a larger example provided for the PermissionSet class.

C#
// Create a second permission set and compare it to the first permission set.
ps2.AddPermission(
    new EnvironmentPermission(EnvironmentPermissionAccess.Read, "USERNAME"));
ps2.AddPermission(
    new EnvironmentPermission(EnvironmentPermissionAccess.Write, "COMPUTERNAME"));
IEnumerator list =  ps1.GetEnumerator();
Console.WriteLine("Permissions in first permission set:");
while (list.MoveNext())
    Console.WriteLine(list.Current.ToString());
Console.WriteLine("Second permission IsSubsetOf first permission = " + ps2.IsSubsetOf(ps1));

Remarks

A PermissionSet is a subset of the target PermissionSet if all demands that succeed for the PermissionSet also succeed for the target. That is, the target contains at least the permissions contained in the subset.

Applies to

Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)