当前位置: 首页>>代码示例>>C#>>正文


C# AssemblyDefinitionDynamic.Save方法代码示例

本文整理汇总了C#中AssemblyDefinitionDynamic.Save方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyDefinitionDynamic.Save方法的具体用法?C# AssemblyDefinitionDynamic.Save怎么用?C# AssemblyDefinitionDynamic.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AssemblyDefinitionDynamic的用法示例。


在下文中一共展示了AssemblyDefinitionDynamic.Save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compile


//.........这里部分代码省略.........
            tr.Start (TimeReporter.TimerType.AssemblyBuilderSetup);
            var assembly = new AssemblyDefinitionStatic (module, references_loader, output_file_name, output_file);
            assembly.Create (references_loader.Domain);
            tr.Stop (TimeReporter.TimerType.AssemblyBuilderSetup);

            // Create compiler types first even before any referenced
            // assembly is loaded to allow forward referenced types from
            // loaded assembly into compiled builder to be resolved
            // correctly
            tr.Start (TimeReporter.TimerType.CreateTypeTotal);
            module.CreateType ();
            importer.AddCompiledAssembly (assembly);
            tr.Stop (TimeReporter.TimerType.CreateTypeTotal);

            references_loader.LoadReferences (module);

            tr.Start (TimeReporter.TimerType.PredefinedTypesInit);
            if (!ctx.BuildinTypes.CheckDefinitions (module))
                return false;

            tr.Stop (TimeReporter.TimerType.PredefinedTypesInit);

            references_loader.LoadModules (assembly, module.GlobalRootNamespace);
            #else
            var assembly = new AssemblyDefinitionDynamic (module, output_file_name, output_file);
            module.SetDeclaringAssembly (assembly);

            var importer = new ReflectionImporter (module, ctx.BuildinTypes);
            assembly.Importer = importer;

            var loader = new DynamicLoader (importer, ctx);
            loader.LoadReferences (module);

            if (!ctx.BuildinTypes.CheckDefinitions (module))
                return false;

            if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Run))
                return false;

            module.CreateType ();

            loader.LoadModules (assembly, module.GlobalRootNamespace);
            #endif
            tr.Start (TimeReporter.TimerType.ModuleDefinitionTotal);
            module.Define ();
            tr.Stop (TimeReporter.TimerType.ModuleDefinitionTotal);

            if (Report.Errors > 0)
                return false;

            //if (settings.Documentation != null &&
            //    !settings.Documentation.OutputDocComment (
            //        output_file, Report))
            //    return false;

            //
            // Verify using aliases now
            //
            tr.Start (TimeReporter.TimerType.UsingVerification);
            NamespaceEntry.VerifyAllUsing ();
            tr.Stop (TimeReporter.TimerType.UsingVerification);

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

            assembly.Resolve ();

            if (Report.Errors > 0)
                return false;

            tr.Start (TimeReporter.TimerType.EmitTotal);
            assembly.Emit ();
            tr.Stop (TimeReporter.TimerType.EmitTotal);

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

            tr.Start (TimeReporter.TimerType.CloseTypes);
            module.CloseType ();
            tr.Stop (TimeReporter.TimerType.CloseTypes);

            tr.Start (TimeReporter.TimerType.Resouces);
            assembly.EmbedResources ();
            tr.Stop (TimeReporter.TimerType.Resouces);

            if (Report.Errors > 0)
                return false;

            assembly.Save ();

            #if STATIC
            references_loader.Dispose ();
            #endif
            tr.StopTotal ();
            tr.ShowStats ();

            return Report.Errors == 0;
        }
开发者ID:RainsSoft,项目名称:MonoCompilerAsAService,代码行数:101,代码来源:driver.cs

示例2: Compile

		//
		// Main compilation method
		//
		public bool Compile ()
		{
			var module = new ModuleContainer (ctx);
			RootContext.ToplevelTypes = module;

			if (timestamps) {
				stopwatch = Stopwatch.StartNew ();
				first_time = DateTime.Now;
			}

			Parse (module);
			ShowTime ("Parsing source files");

			if (Report.Errors > 0)
				return false;

			if (RootContext.TokenizeOnly || RootContext.ParseOnly)
				return true;

			if (RootContext.ToplevelTypes.NamespaceEntry != null)
				throw new InternalErrorException ("who set it?");

			//
			// Quick hack
			//
			var output_file = RootContext.OutputFile;
			string output_file_name;
			if (output_file == null) {
				if (first_source == null) {
					Report.Error (1562, "If no source files are specified you must specify the output file with -out:");
					return false;
				}

				int pos = first_source.LastIndexOf ('.');

				if (pos > 0)
					output_file = first_source.Substring (0, pos) + RootContext.TargetExt;
				else
					output_file = first_source + RootContext.TargetExt;

				output_file_name = output_file;
			} else {
				output_file_name = Path.GetFileName (output_file);
			}

			//
			// Load assemblies required
			//
			if (timestamps)
				stopwatch = Stopwatch.StartNew ();

#if STATIC
			var assembly = new AssemblyDefinitionStatic (module, output_file_name, output_file);
			module.SetDeclaringAssembly (assembly);

			var importer = new StaticImporter ();
			assembly.Importer = importer;

			var loader = new StaticLoader (importer, ctx);
			loader.LoadReferences (module);

			ShowTime ("Imporing referenced assemblies");

			if (!ctx.BuildinTypes.CheckDefinitions (module))
				return false;

			ShowTime ("Initializing predefined types");

			if (!assembly.Create (loader))
				return false;

			// System.Object was not loaded, use compiled assembly as corlib
			if (loader.Corlib == null)
				loader.Corlib = assembly.Builder;

			loader.LoadModules (assembly, module.GlobalRootNamespace);
#else
			var assembly = new AssemblyDefinitionDynamic (module, output_file_name, output_file);
			module.SetDeclaringAssembly (assembly);

			var importer = new ReflectionImporter (ctx.BuildinTypes);
			assembly.Importer = importer;

			var loader = new DynamicLoader (importer, ctx);
			loader.LoadReferences (module);

			ShowTime ("Imporing referenced assemblies");

			if (!ctx.BuildinTypes.CheckDefinitions (module))
				return false;

			ShowTime ("Initializing predefined types");

			if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Save))
				return false;

			loader.LoadModules (assembly, module.GlobalRootNamespace);
//.........这里部分代码省略.........
开发者ID:litoMalone,项目名称:mono,代码行数:101,代码来源:driver.cs


注:本文中的AssemblyDefinitionDynamic.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。