Preventing JIT inlining on a method

后端 未结 2 1919
遥遥无期
遥遥无期 2020-11-29 06:15

I\'ve got sort of a unique situation. I\'ve been working on an open source library for sending email. In this library, I need a reliable way to get the calling method. I\

2条回答
  •  庸人自扰
    2020-11-29 06:50

    You could use MethodImplAttribute and specify MethodImplOptions.NoInlining.

    [MethodImpl(MethodImplOptions.NoInlining)]
    void YourMethod()
    {
        // do something
    }
    

    Note that this still doesn't guarantee that you can get at the actual calling method as seen in the source code. Your method won't be inlined, but your method's caller could be inlined into its own caller, etc etc.

提交回复
热议问题