ReflectionPermission ReflectionPermission ReflectionPermission ReflectionPermission Class

定义

通过 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
继承
ReflectionPermissionReflectionPermissionReflectionPermissionReflectionPermission
属性
实现

注解

无需ReflectionPermission,代码可以使用反射来访问对象的公共成员。Without ReflectionPermission, code can use reflection to access only the public members of objects. 使用代码ReflectionPermission适当ReflectionPermissionFlag标志可以访问protectedprivate对象的成员。Code with ReflectionPermission and the appropriate ReflectionPermissionFlag flags can access the protected and private members of objects.

注意

因为ReflectionPermission可以提供访问非公共类型和成员,我们建议不要授予ReflectionPermission到 Internet 的代码中,除了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.

反射的某些功能发出,例如发出调试符号,需要ReflectionPermissionReflectionPermissionFlag.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(PermissionState) ReflectionPermission(PermissionState) ReflectionPermission(PermissionState)

用指定的完全受限制或不受限制的权限初始化 ReflectionPermission 类的新实例。Initializes a new instance of the ReflectionPermission class with either fully restricted or unrestricted permission as specified.

ReflectionPermission(ReflectionPermissionFlag) ReflectionPermission(ReflectionPermissionFlag) ReflectionPermission(ReflectionPermissionFlag) ReflectionPermission(ReflectionPermissionFlag)

用指定的访问权限初始化 ReflectionPermission 类的新实例。Initializes a new instance of the ReflectionPermission class with the specified access.

属性

Flags Flags Flags Flags

获取或设置允许用于当前权限的反射类型。Gets or sets the type of reflection allowed for the current permission.

方法

Assert() Assert() Assert() 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.

(Inherited from CodeAccessPermission)
Copy() Copy() Copy() Copy()

创建并返回当前权限的相同副本。Creates and returns an identical copy of the current permission.

Demand() Demand() Demand() 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.

(Inherited from CodeAccessPermission)
Deny() Deny() Deny() 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.

(Inherited from CodeAccessPermission)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的 CodeAccessPermission 对象是否等于当前的 CodeAccessPermissionDetermines whether the specified CodeAccessPermission object is equal to the current CodeAccessPermission.

(Inherited from CodeAccessPermission)
FromXml(SecurityElement) FromXml(SecurityElement) FromXml(SecurityElement) FromXml(SecurityElement)

从 XML 编码重新构造具有指定状态的权限。Reconstructs a permission with a specified state from an XML encoding.

GetHashCode() GetHashCode() GetHashCode() 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.

(Inherited from CodeAccessPermission)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
Intersect(IPermission) Intersect(IPermission) Intersect(IPermission) Intersect(IPermission)

创建并返回一个权限,该权限是当前权限和指定权限的交集。Creates and returns a permission that is the intersection of the current permission and the specified permission.

IsSubsetOf(IPermission) IsSubsetOf(IPermission) IsSubsetOf(IPermission) IsSubsetOf(IPermission)

确定当前权限是否为指定权限的子集。Determines whether the current permission is a subset of the specified permission.

IsUnrestricted() IsUnrestricted() IsUnrestricted() IsUnrestricted()

返回一个值,该值指示当前权限是否为无限制的。Returns a value indicating whether the current permission is unrestricted.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
PermitOnly() PermitOnly() PermitOnly() 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.

(Inherited from CodeAccessPermission)
ToString() ToString() ToString() ToString()

创建并返回当前权限对象的字符串表示形式。Creates and returns a string representation of the current permission object.

(Inherited from CodeAccessPermission)
ToXml() ToXml() ToXml() ToXml()

创建权限及其当前状态的 XML 编码。Creates an XML encoding of the permission and its current state.

Union(IPermission) Union(IPermission) Union(IPermission) Union(IPermission)

创建一个权限,该权限是当前权限与指定权限的并集。Creates a permission that is the union of the current permission and the specified permission.

显式界面实现

IPermission.Demand() IPermission.Demand() IPermission.Demand() IPermission.Demand() Inherited from CodeAccessPermission
IStackWalk.Assert() IStackWalk.Assert() IStackWalk.Assert() IStackWalk.Assert() Inherited from CodeAccessPermission
IStackWalk.Demand() IStackWalk.Demand() IStackWalk.Demand() IStackWalk.Demand() Inherited from CodeAccessPermission
IStackWalk.Deny() IStackWalk.Deny() IStackWalk.Deny() IStackWalk.Deny() Inherited from CodeAccessPermission
IStackWalk.PermitOnly() IStackWalk.PermitOnly() IStackWalk.PermitOnly() IStackWalk.PermitOnly() Inherited from CodeAccessPermission

适用于

另请参阅