如何在.NET中MethodImplAttribute工作? [英] How does the MethodImplAttribute work in .NET?
问题描述
我正在调查一些框架code(在System.AppDomain.GetDynamicDir法),这是所有的汇编显示:
I was investigating some framework code (the System.AppDomain.GetDynamicDir method) and this was all the assembler showed:
[MethodImpl(MethodImplOptions.InternalCall)]
private extern string GetDynamicDir();
在调用此方法时会发生什么情况?我不是说这个特定的方法,但方法与这个属性一般。
What happens when this method is called? I don't mean this specific method, but methods with this attribute in general.
推荐答案
从<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.methodimploptions.aspx">MSDN:
MethodImplOptions.InternalCall :指定一个内部 呼叫。内部呼叫是一个 即内实现的方法 公共语言运行时本身。
MethodImplOptions.InternalCall: Specifies an internal call. An internal call is a call to a method that is implemented within the common language runtime itself.
因此,基本上,CLR提供了自己的此方法的实现(这可能是在本地code),这就是为什么你不能看到它的反汇编。
So basically, the CLR provides its own implementation of this method (which is probably in native code), which is why you can't see it in the disassembler.
这篇关于如何在.NET中MethodImplAttribute工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!