MethodImplOptions 枚举


定义如何实现方法的详细信息。Defines the details of how a method is implemented.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class MethodImplOptions
public enum MethodImplOptions
type MethodImplOptions = 
Public Enum MethodImplOptions


AggressiveInlining 256

如可能应将该方法进行内联。The method should be inlined if possible.

AggressiveOptimization 512

此方法包含一个热路径,且应进行优化。The method contains a hot path and should be optimized.

ForwardRef 16

已声明该方法,但在其他位置提供实现。The method is declared, but its implementation is provided elsewhere.

InternalCall 4096

该调用为内部调用,也就是说它调用了在公共语言运行时中实现的方法。The call is internal, that is, it calls a method that is implemented within the common language runtime.

NoInlining 8

该方法不能为内联方法。The method cannot be inlined. 内联是一种优化方式,通过该方式将方法调用替换为方法体。Inlining is an optimization by which a method call is replaced with the method body.

NoOptimization 64

调试可能的代码生成问题时,该方法不由实时 (JIT) 编译器或本机代码生成优化(请参阅 Ngen.exe)。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.

PreserveSig 128

完全按照声明导出方法签名。The method signature is exported exactly as declared.

SecurityMitigations 1024

JIT 编译器应查找安全缓解属性,例如用户定义的 System.Runtime.CompilerServices.SecurityMitigationsAttributeThe 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 32

该方法一次性只能在一个线程上执行。The method can be executed by only one thread at a time. 静态方法在类型上锁定,而实例方法在实例上锁定。Static methods lock on the type, whereas instance methods lock on the instance. 只有一个线程可在任意实例函数中执行,且只有一个线程可在任意类的静态函数中执行。Only one thread can execute in any of the instance functions, and only one thread can execute in any of a class's static functions.

Unmanaged 4

此方法在非托管的代码中实现。The method is implemented in unmanaged code.


此枚举与MethodImplAttribute属性一起使用。This enumeration is used with the MethodImplAttribute attribute.

可以使用按位MethodImplOptions "或" 运算符指定多个值。You can specify multiple MethodImplOptions values by using the bitwise OR operator.


对于公共类型, 不建议锁定实例或类型上的 (与同步标志相同), 因为非自己的代码可以对公共类型和实例进行锁定。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.