共用方式為


PermissionSet.SetPermission(IPermission) 方法

定義

將權限設定為 PermissionSet,以取代任何相同類型的現有權限。

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);
public virtual System.Security.IPermission SetPermission (System.Security.IPermission perm);
public System.Security.IPermission SetPermission (System.Security.IPermission perm);
member this.SetPermission : System.Security.IPermission -> System.Security.IPermission
abstract member SetPermission : System.Security.IPermission -> System.Security.IPermission
override this.SetPermission : System.Security.IPermission -> System.Security.IPermission
Public Function SetPermission (perm As IPermission) As IPermission
Public Overridable Function SetPermission (perm As IPermission) As IPermission

參數

perm
IPermission

要設定的權限。

傳回

已設定的權限。

例外狀況

範例

下列程式代碼範例示範 如何使用 SetPermission 方法。 此程式代碼範例是提供給 類別之較大範例的 PermissionSet 一部分。

// Change the permission set using SetPermission.
ps5->SetPermission( gcnew EnvironmentPermission( EnvironmentPermissionAccess::AllAccess,"USERNAME" ) );
Console::WriteLine( "Permission set after SetPermission = {0}", ps5 );
// Change the permission set using SetPermission.
ps5.SetPermission(new EnvironmentPermission(EnvironmentPermissionAccess.AllAccess, "USERNAME"));
Console.WriteLine("Permission set after SetPermission = " + ps5.ToString());
' Change the permission set using SetPermission.
ps5.SetPermission(New EnvironmentPermission(EnvironmentPermissionAccess.AllAccess, "USERNAME"))
Console.WriteLine("Permission set after SetPermission = " & ps5.ToString())

備註

這個方法會從 PermissionSet 中移除相同類型的任何現有許可權物件,並將它取代為 perm 參數。 如果實作IUnrestrictedPermission的權限設定在 為Unrestricted的 上PermissionSet,則產生的 PermissionSet 不再是 Unrestricted

給繼承者的注意事項

當您繼承自 PermissionSet時,可以藉由覆SetPermissionImpl(IPermission)寫 方法來變更 方法的行為SetPermission(IPermission)

適用於