Using [MethodImpl(MethodImplOptions.NoInlining)] decoration for a method RRS feed

  • Question

  • Can someone please explain me when do we use the [MethodImpl(MethodImplOptions.NoInlining)] decoration for a method and how does it helps? When do we use these different options avilable in MethodImplOptions?
    Saturday, May 9, 2009 6:15 AM


  • Exception handling.  A common scenario in libraries is a small public method that invokes internal class methods that are not visible to the client.  Such a small method would be inlined.  When the internal code throws an exception, the stack trace of the exception only shows the internal methods.  Not giving the client much of a chance to guess how the code got there.

    With the [MethodImpl] attribute, inlining is suppressed and that small public method will appear in the stack trace.  You'd only do this if the cost of not inlining the method is small compared to the cost of executing the internal code.  Which is common.

    Hans Passant.
    • Marked as answer by Marco Zhou Tuesday, May 12, 2009 6:29 AM
    Saturday, May 9, 2009 10:42 AM