简体   繁体   English

为什么此反汇编代码无法在C#中编译?

[英]Why does this disassembled code not compile in C#?

I recovered the following class from a CIL to C# converter (.Net reflector). 我从CIL到C#转换器(.Net反射器)恢复了以下类。 Unfortunately, VS2010 won't compile it. 不幸的是,VS2010无法编译它。 Any idea how I can make it work? 知道如何使它起作用吗?

using System;
using System.IO;
using System.Reflection;
internal class <Module>
{
    static <Module>()
    {
        IPLRes.ExeDirectory = new FileInfo(Assembly.GetExecutingAssembly>>().Location).DirectoryName;
        AppDomain expr_1E = AppDomain.CurrentDomain;
        expr_1E.AssemblyResolve += new ResolveEventHandler(expr_1E.AssemblyNotFound);
        IPLRes.LogDirectory = IPLRes.ExeDirectory + "\\log";
        IPLMsg.Log("Loader", "Application starting...");
    }
    public static Assembly AssemblyNotFound(object A_0, ResolveEventArgs A_1)
    {
        string text = A_1.Name;
        text = text.Remove(text.IndexOf(","));
        text = IPLRes.ExeDirectory + "\\bin35\\" + text + ".dll";
        return Assembly.LoadFile(text);
    }
    [STAThread]
    public static void IPLMain(string[] A_0)
    {
        if (A_0.Length >= 1)
        {
            IPLRes.BatchMode = A_0[0].Contains("batch");
        }
        if (!IPLRes.BatchMode)
        {
            IPLRes.ShowSplash("ipl_splash.png");
        }
        string[] array = new string[]
        {
            "-X:FullFrames", 
            "-X:Python30", 
            "-c", 
            IPLRes.GetString("ipl_entrypoint35.py")
        };
        IPLMsg.Log("Loader", "Starting main interpreter");
        IPLRes.MainInterpreter = new IronPythonHost();
        if (IPLRes.MainInterpreter.Run(array) != 0)
        {
            array = new string[]
            {
                "-c", 
                IPLRes.GetString("ipl_crash.py")
            };
            IPLMsg.Log("Loader", "Starting crash handler interpreter");
            IPLRes.CrashInterpreter = new IronPythonHost();
            IPLRes.CrashInterpreter.Run(array);
        }
        IPLMsg.Log("Loader", "Application shutting down.");
        IPLMsg.DumpLogFile();
    }
}

That's a module initializer, which C# does not support. 那是模块初始化器,C#不支持。

You can put it in the Main() instead. 您可以将其放在Main()中。
You will need to move the rest of Main() to a separate method so that it can be JITted after adding the AssemblyResolve handler. 您将需要将Main()的其余部分移至单独的方法,以便在添加AssemblyResolve处理程序后可以将其JITted。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM