MethodImplAttributes MethodImplAttributes MethodImplAttributes MethodImplAttributes Enum

定義

指定方法實作的屬性旗標。Specifies flags for the attributes of a method implementation.

此列舉具有 FlagsAttribute 個屬性允許以位元方式合併其成員值。

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

public enum class MethodImplAttributes
[System.Runtime.InteropServices.ComVisible(true)]
[System.Flags]
[System.Serializable]
public enum MethodImplAttributes
type MethodImplAttributes = 
Public Enum MethodImplAttributes
繼承
MethodImplAttributesMethodImplAttributesMethodImplAttributesMethodImplAttributes
屬性

欄位

AggressiveInlining AggressiveInlining AggressiveInlining AggressiveInlining 256

指定可行時應內嵌方法。Specifies that the method should be inlined wherever possible.

AggressiveOptimization AggressiveOptimization AggressiveOptimization AggressiveOptimization 512

指定可行時應最佳化的方法。Specifies that the method should be optimized whenever possible.

CodeTypeMask CodeTypeMask CodeTypeMask CodeTypeMask 3

指定有關程式碼類型的旗標。Specifies flags about code type.

ForwardRef ForwardRef ForwardRef ForwardRef 16

指定方法未定義。Specifies that the method is not defined.

IL IL IL IL 0

指定方法以 Microsoft 中繼語言 (MSIL) 實作。Specifies that the method implementation is in Microsoft intermediate language (MSIL).

InternalCall InternalCall InternalCall InternalCall 4096

指定內部呼叫。Specifies an internal call.

Managed Managed Managed Managed 0

指定方法是以 Managed 程式碼實作。Specifies that the method is implemented in managed code.

ManagedMask ManagedMask ManagedMask ManagedMask 4

指定方法是以 Managed 或 Unmanaged 程式碼實作。Specifies whether the method is implemented in managed or unmanaged code.

MaxMethodImplVal MaxMethodImplVal MaxMethodImplVal MaxMethodImplVal 65535

指定範圍檢查值。Specifies a range check value.

Native Native Native Native 1

指定方法實作為原生。Specifies that the method implementation is native.

NoInlining NoInlining NoInlining NoInlining 8

指定方法無法內嵌。Specifies that the method cannot be inlined.

NoOptimization NoOptimization NoOptimization NoOptimization 64

指定對可能的程式碼產生問題進行偵錯時,方法不是由 Just-In-Time (JIT) 編譯器或原生程式碼產生最佳化 (請參閱 Ngen.exe)。Specifies that the method is not optimized by the just-in-time (JIT) compiler or by native code generation (see Ngen.exe) when debugging possible code generation problems.

OPTIL OPTIL OPTIL OPTIL 2

指定方法以最佳化中繼語言 (OPTIL) 實作。Specifies that the method implementation is in Optimized Intermediate Language (OPTIL).

PreserveSig PreserveSig PreserveSig PreserveSig 128

指定方法簽章完全依宣告方式匯出。Specifies that the method signature is exported exactly as declared.

Runtime Runtime Runtime Runtime 3

指定方法實作由執行階段提供。Specifies that the method implementation is provided by the runtime.

SecurityMitigations SecurityMitigations SecurityMitigations SecurityMitigations 1024

指定 JIT 編譯器應該尋找安全性風險降低屬性,例如使用者定義的 System.Runtime.CompilerServices.SecurityMitigationsAttributeSpecifies that the JIT compiler should look for security mitigation attributes, such as the user-defined System.Runtime.CompilerServices.SecurityMitigationsAttribute. 如果找不到,JIT 編譯器會套用任何相關的安全性風險降低功能。If found, the JIT compiler applies any related security mitigations. 從 .NET Framework 4.8 開始可供使用。Available starting with .NET Framework 4.8.

Synchronized Synchronized Synchronized Synchronized 32

指定方法是單一執行緒,透過主體。Specifies that the method is single-threaded through the body. 靜態方法 (Visual Basic 中的Shared ) 鎖定類型,執行個體方法則鎖定執行個體。Static methods (Shared in Visual Basic) lock on the type, whereas instance methods lock on the instance. 針對此目的,您也可以使用 C# lock 陳述式 或 Visual Basic SyncLock 陳述式You can also use the C# lock statement or the Visual Basic SyncLock statement for this purpose.

Unmanaged Unmanaged Unmanaged Unmanaged 4

指定方法是以 Unmanaged 程式碼實作。Specifies that the method is implemented in unmanaged code.

備註

屬性會使用位 OR 運算結合, 如下所示:The attributes are combined using the bitwise OR operation as follows:

程式碼執行遮罩:Code implementation masks:

  • CodeTypeMask

  • IL

  • Native

  • OPTIL

  • Runtime

受控遮罩:Managed masks:

  • ManagedMask

  • Unmanaged

  • Managed

執行資訊和 interop 遮罩:Implementation information and interop masks:

  • ForwardRef

  • PreserveSig

  • InternalCall

  • Synchronized

  • NoInlining

  • NoOptimization

  • MaxMethodImplVal

  • SecurityMitigations(從 .NET Framework 4.8 開始提供)。SecurityMitigations (Available starting with .NET Framework 4.8.)

注意

對於公用類型, 不建議在實例上或在類型Synchronized上鎖定, 就像使用旗標一樣, 因為您自己以外的程式碼可以在公用類型和實例上取得鎖定。Locking on the instance or on the type, as with the Synchronized flag, is not recommended for public types, because code other than your own can take locks on public types and instances. 這可能會導致鎖死或其他同步處理問題。This might cause deadlocks or other synchronization problems.

適用於

另請參閱