单是否支持"模块的初始化"?初始化、模块、QUOT

2023-09-06 18:57:44 作者:可以很酷

只是好奇,如果单有对模块的初始化的支持? http://blogs.msdn.com/b/junfeng /archive/2005/11/19/494914.aspx

Just curious if mono has support for "Module Initializers"? http://blogs.msdn.com/b/junfeng/archive/2005/11/19/494914.aspx

推荐答案

是的。

我不知道IL,但我在C#

I don't know IL, but I wrote this in C#

using System;
public class Program {
    public static void Main(string[] args) {
        Console.WriteLine("Main");
    }  
}

然后我用monodis产生IL文件,我说这code中的.module MAIN.EXE行之后。

I then used monodis to generate the il file and I added this code after the .module main.exe line.

.method assembly specialname rtspecialname static
  void .cctor() cil managed
{
   .maxstack 8
   IL_0000:  ldstr "module method"
   IL_0005:  call void class [mscorlib]System.Console::WriteLine(string)
   IL_000a:  ret
}

和当它运行时,我得到的输出的预期。

And when it runs I get the output expected.

module method
Main

无论ILASM和运行支持。

Both ilasm and the runtime supports it.