共用方式為


PermissionSet.RemovePermission(Type) 方法

定義

從集合中移除特定類型的權限。

public:
 System::Security::IPermission ^ RemovePermission(Type ^ permClass);
public:
 virtual System::Security::IPermission ^ RemovePermission(Type ^ permClass);
public System.Security.IPermission RemovePermission (Type permClass);
public System.Security.IPermission? RemovePermission (Type? permClass);
public virtual System.Security.IPermission RemovePermission (Type permClass);
member this.RemovePermission : Type -> System.Security.IPermission
abstract member RemovePermission : Type -> System.Security.IPermission
override this.RemovePermission : Type -> System.Security.IPermission
Public Function RemovePermission (permClass As Type) As IPermission
Public Overridable Function RemovePermission (permClass As Type) As IPermission

參數

permClass
Type

要刪除之權限的類型。

傳回

從集合中移除的權限。

例外狀況

範例

下列程式碼範例示範如何使用 RemovePermission 方法來從許可權集合中移除 FileIOPermission 。 此程式碼範例是針對 類別提供的較大範例的 PermissionSet 一部分。

// Remove FileIOPermission from the permission set.
ps5->RemovePermission( FileIOPermission::typeid );
Console::WriteLine( "The last permission set after removing FileIOPermission = {0}", ps5 );
// Remove FileIOPermission from the permission set.
ps5.RemovePermission(typeof(FileIOPermission));
Console.WriteLine("The last permission set after removing FileIOPermission = "
    + ps5.ToString());
' Remove FileIOPermission from the permission set.
ps5.RemovePermission(GetType(FileIOPermission))
Console.WriteLine("The last permission set after removing FileIOPermission = " & ps5.ToString())

備註

重要

您無法從不受限制的許可權集合中移除許可權。 在您嘗試移除許可權之後,許可權集合會保持不受限制,而且不會擲回例外狀況。

下列 C# 程式碼會嘗試從 FullTrust 許可權集合中移除 FileIOPermission ,但不會移除許可權。

PolicyLevel myPol = PolicyLevel.CreateAppDomainLevel();  
PermissionSet myPermSet = myPol.GetNamedPermissionSet("FullTrust");  
myPermSet.RemovePermission(typeof(FileIOPermission));  

給繼承者的注意事項

當您繼承自 PermissionSet 時,可以覆寫 RemovePermissionImpl(Type) 方法來變更 方法的行為 RemovePermission(Type)

適用於