Does Mono support “Module Initializers”?

2019-08-06 12:32发布

问题:

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

回答1:

Yes.

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");
    }  
}

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

Both ilasm and the runtime supports it.



标签: .net mono