ReflectionPermission 類別

定義

控制透過 System.Reflection API 對非公用型別和成員的存取。Controls access to non-public types and members through the System.Reflection APIs. 控制 System.Reflection.Emit API 的一些功能。Controls some features of the System.Reflection.Emit APIs.

public ref class ReflectionPermission sealed : System::Security::CodeAccessPermission, System::Security::Permissions::IUnrestrictedPermission
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public sealed class ReflectionPermission : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
type ReflectionPermission = class
    inherit CodeAccessPermission
    interface IUnrestrictedPermission
Public NotInheritable Class ReflectionPermission
Inherits CodeAccessPermission
Implements IUnrestrictedPermission
繼承
ReflectionPermission
屬性
實作

備註

ReflectionPermission沒有,程式碼可以使用反映來存取物件的公用成員。Without ReflectionPermission, code can use reflection to access only the public members of objects. 具有ReflectionPermission和適當ReflectionPermissionFlag旗標的程式碼可以protected存取private物件的和成員。Code with ReflectionPermission and the appropriate ReflectionPermissionFlag flags can access the protected and private members of objects.

警告

因為ReflectionPermission可以提供對非公用類型和成員的存取權,所以我們建議您不要授ReflectionPermission與網際網路程式ReflectionPermissionFlag.RestrictedMemberAccess代碼,除非有旗標。Because ReflectionPermission can provide access to non-public types and members, we recommend that you do not grant ReflectionPermission to Internet code, except with the ReflectionPermissionFlag.RestrictedMemberAccess flag. RestrictedMemberAccess允許存取非公用成員,限制非公用成員的授與集必須等於存取非公用成員之程式碼的授與集,或其子集。RestrictedMemberAccess allows access to non-public members, with the restriction that the grant set of the non-public members must be equal to, or a subset of, the grant set of the code that accesses the non-public members.

反映發出的某些功能(例如發出 debug 符號)需要ReflectionPermission ReflectionPermissionFlag.ReflectionEmit使用旗標。Certain features of reflection emit, such as emitting debug symbols, require ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit flag.

如需詳細資訊,請參閱 ReflectionPermissionFlag 列舉。For more information, see the ReflectionPermissionFlag enumeration.

建構函式

ReflectionPermission(PermissionState)

使用指定的完全受限制或不受限制的使用權限,來初始化 ReflectionPermission 類別的新執行個體。Initializes a new instance of the ReflectionPermission class with either fully restricted or unrestricted permission as specified.

ReflectionPermission(ReflectionPermissionFlag)

使用指定陣列,初始化 ReflectionPermission 類別的新執行個體。Initializes a new instance of the ReflectionPermission class with the specified access.

屬性

Flags

取得或設定允許目前使用權限的反映型別。Gets or sets the type of reflection allowed for the current permission.

方法

Assert()

宣告即使堆疊中較高層的呼叫端未獲得資源存取權限,呼叫程式碼仍可透過呼叫這個方法的程式碼要求權限,來存取受保護的資源。Declares that the calling code can access the resource protected by a permission demand through the code that calls this method, even if callers higher in the stack have not been granted permission to access the resource. 使用 Assert() 會造成安全性問題。Using Assert() can create security issues.

(繼承來源 CodeAccessPermission)
Copy()

建立並傳回目前權限的相同複本。Creates and returns an identical copy of the current permission.

Demand()

如果在呼叫堆疊中較高的所有呼叫端都尚未被授與由目前執行個體所指定之權限,則會在執行階段強制執行 SecurityExceptionForces a SecurityException at run time if all callers higher in the call stack have not been granted the permission specified by the current instance.

(繼承來源 CodeAccessPermission)
Deny()

防止呼叫堆疊中較高的呼叫端,使用程式碼呼叫此方法來存取目前執行個體所指定的資源。Prevents callers higher in the call stack from using the code that calls this method to access the resource specified by the current instance.

(繼承來源 CodeAccessPermission)
Equals(Object)

判斷指定的 CodeAccessPermission 物件是否等於目前的 CodeAccessPermissionDetermines whether the specified CodeAccessPermission object is equal to the current CodeAccessPermission.

(繼承來源 CodeAccessPermission)
FromXml(SecurityElement)

透過 XML 編碼,重新建構具有指定狀態的權限。Reconstructs a permission with a specified state from an XML encoding.

GetHashCode()

取得 CodeAccessPermission 物件的雜湊碼,其適合用於雜湊表這類的雜湊演算法和資料結構。Gets a hash code for the CodeAccessPermission object that is suitable for use in hashing algorithms and data structures such as a hash table.

(繼承來源 CodeAccessPermission)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
Intersect(IPermission)

建立並傳回目前權限與指定權限交集的權限。Creates and returns a permission that is the intersection of the current permission and the specified permission.

IsSubsetOf(IPermission)

判斷目前權限是否為指定權限的子集。Determines whether the current permission is a subset of the specified permission.

IsUnrestricted()

傳回值,指出目前的權限是否不受限制。Returns a value indicating whether the current permission is unrestricted.

MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
PermitOnly()

防止呼叫堆疊中較高的呼叫端,使用程式碼呼叫此方法來存取目前執行個體所指定之資源以外的所有資源。Prevents callers higher in the call stack from using the code that calls this method to access all resources except for the resource specified by the current instance.

(繼承來源 CodeAccessPermission)
ToString()

建立並傳回目前使用權限物件的字串表示。Creates and returns a string representation of the current permission object.

(繼承來源 CodeAccessPermission)
ToXml()

建立權限和其目前狀態的 XML 編碼方式。Creates an XML encoding of the permission and its current state.

Union(IPermission)

建立目前權限與指定權限聯集的權限。Creates a permission that is the union of the current permission and the specified permission.

明確介面實作

IPermission.Demand() (繼承來源 CodeAccessPermission)
IStackWalk.Assert() (繼承來源 CodeAccessPermission)
IStackWalk.Demand() (繼承來源 CodeAccessPermission)
IStackWalk.Deny() (繼承來源 CodeAccessPermission)
IStackWalk.PermitOnly() (繼承來源 CodeAccessPermission)

適用於

另請參閱