PermissionSet.SetPermission(IPermission) Method

Definition

Sets a permission to the PermissionSet, replacing any existing permission of the same type.

public System.Security.IPermission? SetPermission (System.Security.IPermission? perm);
public virtual System.Security.IPermission SetPermission (System.Security.IPermission perm);
public System.Security.IPermission SetPermission (System.Security.IPermission perm);

Parameters

perm
IPermission

The permission to set.

Returns

The set permission.

Exceptions

The method is called from a ReadOnlyPermissionSet.

Examples

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

// Change the permission set using SetPermission.
ps5.SetPermission(new EnvironmentPermission(EnvironmentPermissionAccess.AllAccess, "USERNAME"));
Console.WriteLine("Permission set after SetPermission = " + ps5.ToString());

Remarks

This method removes any existing permission object of the same type from the PermissionSet and replaces it with the perm parameter. If a permission that implements IUnrestrictedPermission is set on a PermissionSet that is Unrestricted, the resulting PermissionSet is no longer Unrestricted.

Notes to Inheritors

When you inherit from PermissionSet, you can change the behavior of the SetPermission(IPermission) method by overriding the SetPermissionImpl(IPermission) method.

Applies to

Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)