SuppressUnmanagedCodeSecurityAttribute 类

定义

允许托管代码在不进行堆栈审核的情况下调用到非托管代码。 此类不能被继承。

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
[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
[<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
属性

注解

重要

不再支持部分受信任的代码。 此属性在 .NET Core 中不起作用。

注意

请谨慎使用此属性。 不正确的使用可能会造成安全漏洞。

此属性可以应用于想要调用本机代码的方法,而不会在执行此操作时导致运行时安全检查的性能损失。 调用非托管代码时执行的堆栈遍视在运行时被省略,从而大幅节省性能。 在类中使用此属性可将其应用于所有包含的方法。

通常,每当托管代码调用由 PInvoke 或 COM 互操作 (到本机代码) 的非托管代码时,都需要 UnmanagedCode 权限,以确保所有调用方都具有允许此操作的必要权限。 通过应用此显式属性,开发人员可以在运行时抑制需求。 开发人员必须负责确保转换为非托管代码受到其他方式的充分保护。 对权限的需求 UnmanagedCode 仍将在链接时发生。 例如,如果函数 A 调用函数 B,并且函数 B 标记为 SuppressUnmanagedCodeSecurityAttribute,则会在实时编译期间检查函数 A 的非托管代码权限,但随后不会在运行时检查。

仅当应用于 PInvoke 方法 (或包含 PInvoke 方法的类) 或接口的定义时,此属性才有效,将通过该接口进行互操作调用。 它将在所有其他上下文中被忽略。

此属性可用于实现类,该类通过非托管代码提供对系统资源的访问。 无权访问非托管代码的代码可以使用此属性调用类来访问非托管代码。 仅当具有此属性的类的编写器已将类编程为安全时,这才安全。 如果不是,此属性是危险的,并可能允许滥用使用它的代码。

这不是声明性安全属性,而是派生自 Attribute (的常规属性,而不是 SecurityAttribute) 。

构造函数

SuppressUnmanagedCodeSecurityAttribute()

初始化 SuppressUnmanagedCodeSecurityAttribute 类的新实例。

属性

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。

(继承自 Attribute)
GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

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

将一组名称映射为对应的一组调度标识符。

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

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

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

检索对象提供的类型信息接口的数量(0 或 1)。

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

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于

另请参阅