SuppressUnmanagedCodeSecurityAttribute 类

定义

允许托管代码在不进行堆栈审核的情况下调用到非托管代码。Allows managed code to call into unmanaged code without a stack walk. 此类不能被继承。This class cannot be inherited.

public ref class SuppressUnmanagedCodeSecurityAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Interface | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
public sealed class SuppressUnmanagedCodeSecurityAttribute : Attribute
public sealed class SuppressUnmanagedCodeSecurityAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
public sealed class SuppressUnmanagedCodeSecurityAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Interface | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class SuppressUnmanagedCodeSecurityAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Interface | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)>]
type SuppressUnmanagedCodeSecurityAttribute = class
    inherit Attribute
type SuppressUnmanagedCodeSecurityAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)>]
type SuppressUnmanagedCodeSecurityAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Interface | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type SuppressUnmanagedCodeSecurityAttribute = class
    inherit Attribute
Public NotInheritable Class SuppressUnmanagedCodeSecurityAttribute
Inherits Attribute
继承
SuppressUnmanagedCodeSecurityAttribute
属性

注解

重要

不再支持部分受信任的代码。Partially trusted code is no longer supported. 此属性在 .NET Core 中不起作用。This attribute has no effect in .NET Core.

注意

使用此属性时要格外小心。Use this attribute with extreme care. 使用不当可能会造成安全漏洞。Incorrect use can create security weaknesses.

此特性可应用于要调用本机代码的方法,而不会在执行此操作时导致运行时安全检查的性能损失。This attribute can be applied to methods that want to call into native code without incurring the performance loss of a run-time security check when doing so. 在运行时省略了调用非托管代码时执行的堆栈审核,从而大大节省了性能。The stack walk performed when calling unmanaged code is omitted at run time, resulting in substantial performance savings. 在类中使用此属性会将其应用到所有包含的方法。Using this attribute in a class applies it to all contained methods.

通常情况下,每当托管代码调用由 PInvoke 或 COM 互操作 (到本机代码) 中的非托管代码时,都需要 UnmanagedCode 权限,以确保所有调用方都具有允许此操作所需的权限。Generally, whenever managed code calls into unmanaged code (by PInvoke or COM interop into native code), there is a demand for the UnmanagedCode permission to ensure all callers have the necessary permission to allow this. 通过应用此显式特性,开发人员可在运行时取消该需求。By applying this explicit attribute, developers can suppress the demand at run time. 开发人员必须负责确保转换为非托管代码的工作充分受到其他方法的保护。The developer must take responsibility for assuring that the transition into unmanaged code is sufficiently protected by other means. 权限的需求 UnmanagedCode 仍将在链接时出现。The demand for the UnmanagedCode permission will still occur at link time. 例如,如果函数 A 调用函数 B,并将函数 B 标记为 SuppressUnmanagedCodeSecurityAttribute ,则在实时编译期间将检查函数 a 的非托管代码权限,但不会在运行时检查。For example, if function A calls function B and function B is marked with SuppressUnmanagedCodeSecurityAttribute, function A will be checked for unmanaged code permission during just-in-time compilation, but not subsequently during run time.

仅当应用于 PInvoke 方法 (或包含 PInvoke 方法的类) 或通过其进行互操作调用的接口定义时,此特性才有效。This attribute is only effective when applied to PInvoke methods (or classes that contain PInvoke methods) or the definition of an interface through which interop calls will be made. 它将在所有其他上下文中被忽略。It will be ignored in all other contexts.

此特性可用于实现通过非托管代码提供对系统资源的访问的类。This attribute is useful for implementing a class that provides access to system resources through unmanaged code. 没有访问非托管代码权限的代码可以调用具有此属性的类来访问非托管代码。Code that does not have permission to access unmanaged code can call a class with this attribute to access unmanaged code. 只有具有此特性的类的编写器已经将该类编程为安全类,这才是安全的。This is only safe if the writer of the class with this attribute has programmed the class to be secure. 否则,此属性是危险的,可能会导致使用该属性的代码被滥用。If not, this attribute is dangerous and can allow the code that uses it to be misused.

这不是声明性的安全属性,而是派生自 (的常规属性 Attribute ,而不是 SecurityAttribute) 。This is not a declarative security attribute, but a regular attribute (it derives from Attribute, not SecurityAttribute).

构造函数

SuppressUnmanagedCodeSecurityAttribute()

初始化 SuppressUnmanagedCodeSecurityAttribute 类的新实例。Initializes a new instance of the SuppressUnmanagedCodeSecurityAttribute class.

属性

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)
GetType()

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

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

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

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于