Mono.ILASM.CodeGen.Write C# (CSharp) Метод

Write() публичный Метод

public Write ( ) : void
Результат void
                public void Write ()
                {
                        FileStream out_stream = null;

                        try {
                                if (ThisModule == null)
                                        this_module = new Module (Path.GetFileName (output_file));

                                out_stream = new FileStream (output_file, FileMode.Create, FileAccess.Write);
                                pefile = new PEFile (ThisAssembly != null ? ThisAssembly.Name : null, ThisModule.Name, is_dll, ThisAssembly != null, null, out_stream);
                                PEAPI.Assembly asmb = pefile.GetThisAssembly ();

                                ThisModule.PeapiModule = pefile.GetThisModule ();

                                if (file_ref != null)
                                        file_ref.Resolve (this);

                                extern_table.Resolve (this);
                                type_manager.DefineAll ();

				if (manifestResources != null) {
					foreach (ManifestResource mr in manifestResources)
						pefile.AddManifestResource (mr);
				}

                                foreach (FieldDef fielddef in global_field_table.Values) {
                                        fielddef.Define (this);
                                }

                                foreach (MethodDef methoddef in global_method_table.Values) {
                                        methoddef.Define (this);
                                }

                                foreach (TypeDef typedef in defcont_list) {
                                        typedef.DefineContents (this);
                                }

                                if (ThisAssembly != null)
                                        ThisAssembly.Resolve (this, pefile.GetThisAssembly ());
                                ThisModule.Resolve (this, pefile.GetThisModule ());

                                if (sub_system != -1)
                                        pefile.SetSubSystem ((PEAPI.SubSystem) sub_system);
                                if (cor_flags != -1)
                                        pefile.SetCorFlags (cor_flags);
                                if (stack_reserve != -1)
                                        pefile.SetStackReserve (stack_reserve);

                                pefile.WritePEFile ();

				if (symwriter != null) {
					Guid guid = pefile.GetThisModule ().Guid;
					symwriter.Write (guid);
				}
                        } finally {
                                if (out_stream != null)
                                        out_stream.Close ();
                        }
                }

Usage Example

Пример #1
0
            public bool Run()
            {
                if (il_file_list.Count == 0)
                {
                    Usage();
                }
                if (output_file == null)
                {
                    output_file = CreateOutputFilename();
                }
                try {
                    codegen = new CodeGen(output_file, target == Target.Dll, debugging_info, noautoinherit);
                    foreach (string file_path in il_file_list)
                    {
                        Report.FilePath = file_path;
                        ProcessFile(file_path);
                    }
                    if (scan_only)
                    {
                        return(true);
                    }

                    if (Report.ErrorCount > 0)
                    {
                        return(false);
                    }

                    if (target != Target.Dll && !codegen.HasEntryPoint)
                    {
                        Report.Error("No entry point found.");
                    }

                    // if we have a key and aren't assembling a netmodule
                    if ((keyname != null) && !codegen.IsThisAssembly(null))
                    {
                        LoadKey();
                        // this overrides any attribute or .publickey directive in the source
                        codegen.ThisAssembly.SetPublicKey(sn.PublicKey);
                    }

                    try {
                        codegen.Write();
                    } catch {
                        File.Delete(output_file);
                        throw;
                    }
                } catch (ILAsmException e) {
                    Error(e.ToString());
                    return(false);
                } catch (PEAPI.PEFileException pe) {
                    Error("Error : " + pe.Message);
                    return(false);
                }

                try {
                    if (sn != null)
                    {
                        Report.Message("Signing assembly with the specified strongname keypair");
                        return(Sign(output_file));
                    }
                } catch {
                    return(false);
                }

                return(true);
            }
All Usage Examples Of Mono.ILASM.CodeGen::Write