SuppressUnmanagedCodeSecurityAttribute 類別

定義

允許 Managed 程式碼不經過堆疊查核行程即呼叫 Unmanaged 程式碼。 此類別無法獲得繼承。

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 中沒有任何作用。

警告

請小心使用這個屬性。 不正確的使用可能會造成安全性弱點。

這個屬性可以套用至想要呼叫原生程式碼的方法,而不會在執行時造成執行時間安全性檢查的效能遺失。 在執行時間省略呼叫 Unmanaged 程式碼時所執行的堆疊逐步解說,因而節省大量效能。 在類別中使用這個屬性會將它套用至所有自主方法。

一般而言,每當 Managed 程式碼呼叫 PInvoke 或 COM Interop 對機器碼 (的 Unmanaged 程式碼時,) ,就會要求 UnmanagedCode 許可權,以確保所有呼叫端都有允許此許可權的必要許可權。 藉由套用這個明確屬性,開發人員可以在執行時間隱藏需求。 開發人員必須負責確保轉換至 Unmanaged 程式碼已充分受到其他方式保護。 許可權的需求 UnmanagedCode 仍會在連結時間發生。 例如,如果函式 A 呼叫函式 B,且函式 B 標示 SuppressUnmanagedCodeSecurityAttribute 為 ,則函式 A 會在 Just-In-Time 編譯期間檢查 Unmanaged 程式碼許可權,但在執行時間期間不會後續檢查。

只有在套用至 PInvoke 方法 (或包含 PInvoke 方法的類別時,這個屬性才有效) 或介面的定義,以便進行 Interop 呼叫。 所有其他內容中都會忽略它。

這個屬性很適合用來實作類別,以透過 Unmanaged 程式碼存取系統資源。 沒有存取 Unmanaged 程式碼許可權的程式碼可以呼叫具有這個屬性的類別,以存取 Unmanaged 程式碼。 只有當具有這個屬性的類別寫入器已將類別程式設計為安全時,才安全。 如果沒有,這個屬性會很危險,而且允許使用它的程式碼誤用。

這不是宣告式安全性屬性,但一般屬性 (衍生自 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)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱