CSPspEmu.Gui.Winforms.FunctionViewerForm.saveILAsDLLToolStripMenuItem_Click C# (CSharp) Метод

saveILAsDLLToolStripMenuItem_Click() приватный Метод

private saveILAsDLLToolStripMenuItem_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
Результат void
        private void saveILAsDLLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_DynarecConfig.FunctionCallWithStaticReferences)
            {
                MessageBox.Show("_DynarecConfig.FunctionCallWithStaticReferences enabled. It will break exporting.");
            }

            var nameOfAssembly = "OutputAssembly";
            var nameOfModule = "OutputModule";
            var nameOfDLL = "cspspemu_temp_output.dll";
            var nameOfType = "OutputType";

            var SaveFileDialog = new SaveFileDialog();
            SaveFileDialog.FileName = nameOfDLL;
            SaveFileDialog.DefaultExt = ".dll";
            SaveFileDialog.AddExtension = true;
            var Result = SaveFileDialog.ShowDialog();
            if (Result != System.Windows.Forms.DialogResult.Cancel)
            {
                var AssemblyName = new System.Reflection.AssemblyName { Name = nameOfAssembly };
                var AssemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.Save);
                var ModuleBuilder = AssemblyBuilder.DefineDynamicModule(nameOfModule, nameOfDLL);
                var TypeBuilder = ModuleBuilder.DefineType(nameOfType, TypeAttributes.Public | TypeAttributes.Class);

                //FieldBuilder targetWrapedObjectField = typeBuilder.DefineField("_" + targetWrapType.FullName.Replace(".", ""), targetWrapType, System.Reflection.FieldAttributes.Private);
                //MethodAttributes constructorAttributes = System.Reflection.MethodAttributes.Public;
                //
                //Type objType = Type.GetType("System.Object");
                //ConstructorInfo objCtor = objType.GetConstructor(new Type[0]);
                //ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(constructorAttributes, System.Reflection.CallingConventions.Standard, new Type[] { targetWrapType });
                //System.Reflection.Emit.ILGenerator ilConstructor = constructorBuilder.GetILGenerator();

                foreach (var PC in CpuProcessor.MethodCache.PCs.OrderBy(Item => Item))
                {
                    var Entry = CpuProcessor.MethodCache.GetForPC(PC);
                    if (Entry.AstTree != null)
                    {
                        var MethodBuilder = TypeBuilder.DefineMethod("Method_" + Entry.Name, MethodAttributes.Public | MethodAttributes.Static, typeof(void), new[] { typeof(CpuThreadState) });
                        Entry.AstTree.GenerateIL(MethodBuilder, MethodBuilder.GetILGenerator());
                        //MethodBuilder.CreateDelegate(typeof(Action<CpuThreadState>));
                    }

                    //break;
                }

                TypeBuilder.CreateType();

                AssemblyBuilder.Save(nameOfDLL);
                File.Copy(nameOfDLL, SaveFileDialog.FileName, true);
            }
        }