我有一些依赖于未内联的方法的代码:
internal class MyClass : BaseClass
{
// should not be inlined
public void DoSomething(int id)
{
base.Execute(id);
}
}
public abstract class BaseClass : MarshallByRefObject
{
[MethodImpl(MethodImplOptions.NoInlining)]
protected void Execute(params object[] args)
{
// does a stack walk to find signature of calling method
}
}当然,只有在DoSomething方法没有内联的情况下,这才能起作用。这就是基类从MarshallByRefObject派生的原因,它阻止了公共方法的内联。
到目前为止,它一直有效,但我从.Net 4服务器获得了堆栈跟踪,显示堆栈漫步到达了DoSomething的调用者。
.Net 4内联是不是更聪明,并检测到MyClass是内部的,没有机会被代理替代?
发布于 2012-01-20 21:01:03
这里的评论者建议您还需要指定NoOptimisation来实现您想要的功能。
http://connect.microsoft.com/VisualStudio/feedback/details/162364/methodimpl-methodimploptions-noinlining-doesnt-work-correctly-on-x64
https://stackoverflow.com/questions/8924342
复制相似问题