MethodImpl attribute is a pseudo-attribute. Just to give a quick overview, a pseudo-attribute is not saved in the metadata files as regular attributes but is used to set bits or fields within the metadata.
- Unmanaged: Specifies that the method is implemented in unmanaged code;
- NoInlining: Specifies that the method is not inlined by the JIT;
- ForwardRef: Specifies that the method is declared only but implemented in a different place;
- Synchronized: Has the same behavior than a lock to the whole method indicating that only one thread at a time is allowed to access the method;
- NoOptimization: Specifies that the method is not optimized by the JIT or NGen;
- PreserveSig: Preserve the method signature exporting it exactly as declared;
- InternalCall: Specifies that the call is done to a method implemented within the CLR.
As any other attribute, apply the MethodImpl is pretty straightforward:
public void MyMethodNotInlined()
/// Some code.
public void MySynchronizedMethod()
/// Some code executed by one thread at a time.