PermissionSet Constructors

Definition

Initializes a new instance of the PermissionSet class.

Overloads

PermissionSet(PermissionState)

Initializes a new instance of the PermissionSet class with the specified PermissionState.

PermissionSet(PermissionSet)

Initializes a new instance of the PermissionSet class with initial values taken from the permSet parameter.

PermissionSet(PermissionState)

Source:
PermissionSet.cs
Source:
PermissionSet.cs
Source:
PermissionSet.cs

Initializes a new instance of the PermissionSet class with the specified PermissionState.

C#
public PermissionSet(System.Security.Permissions.PermissionState state);

Parameters

state
PermissionState

One of the enumeration values that specifies the permission set's access to resources.

Exceptions

The state parameter is not a valid PermissionState.

Examples

The following code example shows the use of the PermissionSet constructor to create a permission set with a permission state of None. This code example is part of a larger example provided for the PermissionSet class.

C#
// Open a new PermissionSet.
PermissionSet ps1 = new PermissionSet(PermissionState.None);
Console.WriteLine("Adding permission to open a file from a file dialog box.");
// Add a permission to the permission set.
ps1.AddPermission(
    new FileDialogPermission(FileDialogPermissionAccess.Open));
Console.WriteLine("Demanding permission to open a file.");
ps1.Demand();
Console.WriteLine("Demand succeeded.");

Remarks

The Unrestricted state allows all permissions that implement the IUnrestrictedPermission interface, while None allows no permissions.

Use AddPermission on an empty PermissionSet to define the set in greater detail.

Applies to

.NET 10 and other versions
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)

PermissionSet(PermissionSet)

Source:
PermissionSet.cs
Source:
PermissionSet.cs
Source:
PermissionSet.cs

Initializes a new instance of the PermissionSet class with initial values taken from the permSet parameter.

C#
public PermissionSet(System.Security.PermissionSet? permSet);
C#
public PermissionSet(System.Security.PermissionSet permSet);

Parameters

permSet
PermissionSet

The set from which to take the value of the new PermissionSet, or null to create an empty PermissionSet.

Remarks

The new PermissionSet contains copies of the permissions contained in the specified PermissionSet.

Note

This is equivalent to Copy when the permSet parameter is not null.

Applies to

.NET 10 and other versions
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)