當前位置: 首頁>>代碼示例>>C#>>正文


C# Driver.Compile方法代碼示例

本文整理匯總了C#中Mono.CSharp.Driver.Compile方法的典型用法代碼示例。如果您正苦於以下問題:C# Driver.Compile方法的具體用法?C# Driver.Compile怎麽用?C# Driver.Compile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.CSharp.Driver的用法示例。


在下文中一共展示了Driver.Compile方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: InvokeCompiler

        public static bool InvokeCompiler(string [] args, TextWriter error)
        {
            try {
                CommandLineParser cmd = new CommandLineParser (error);
                var setting = cmd.ParseArguments (args);
                if (setting == null)
                    return false;

                var d = new Driver (new CompilerContext (setting, new StreamReportPrinter (error)));
                return d.Compile ();
            } finally {
                Reset ();
            }
        }
開發者ID:riviti,項目名稱:NRefactory,代碼行數:14,代碼來源:driver.cs

示例2: Compile

            public bool Compile(CompilerOptions options, ErrorReporterWrapper er)
            {
                string intermediateAssemblyFile = Path.GetTempFileName(), intermediateDocFile = Path.GetTempFileName();
                try {
                    // Compile the assembly
                    var settings = MapSettings(options, intermediateAssemblyFile, intermediateDocFile, er);
                    if (er.HasErrors)
                        return false;

                    if (!options.AlreadyCompiled) {
                        // Compile the assembly
                        var ctx = new CompilerContext(settings, new ConvertingReportPrinter(er));
                        var d = new Mono.CSharp.Driver(ctx);
                        d.Compile();
                        if (er.HasErrors)
                            return false;
                    }

                    // Compile the script
                    var md = new MetadataImporter.ScriptSharpMetadataImporter(options.MinimizeScript);
                    var n = new DefaultNamer();
                    PreparedCompilation compilation = null;
                    var rtl = new ScriptSharpRuntimeLibrary(md, er, n.GetTypeParameterName, tr => { var t = tr.Resolve(compilation.Compilation).GetDefinition(); return new JsTypeReferenceExpression(t.ParentAssembly, md.GetTypeSemantics(t).Name); });
                    var compiler = new Compiler.Compiler(md, n, rtl, er, allowUserDefinedStructs: options.References.Count == 0 /* We allow user-defined structs in mscorlib only, which can be identified by the fact that it has no references*/);

                    var references = LoadReferences(settings.AssemblyReferences, er);
                    if (references == null)
                        return false;

                    compilation = compiler.CreateCompilation(options.SourceFiles.Select(f => new SimpleSourceFile(f, settings.Encoding)), references, options.DefineConstants);
                    var compiledTypes = compiler.Compile(compilation);

                    var js = new ScriptSharpOOPEmulator(compilation.Compilation, md, rtl, er).Rewrite(compiledTypes, compilation.Compilation);
                    js = new GlobalNamespaceReferenceImporter().ImportReferences(js);

                    if (er.HasErrors)
                        return false;

                    string outputAssemblyPath = !string.IsNullOrEmpty(options.OutputAssemblyPath) ? options.OutputAssemblyPath : Path.ChangeExtension(options.SourceFiles[0], ".dll");
                    string outputScriptPath   = !string.IsNullOrEmpty(options.OutputScriptPath)   ? options.OutputScriptPath   : Path.ChangeExtension(options.SourceFiles[0], ".js");

                    if (!options.AlreadyCompiled) {
                        try {
                            File.Copy(intermediateAssemblyFile, outputAssemblyPath, true);
                        }
                        catch (IOException ex) {
                            er.Region = DomRegion.Empty;
                            er.Message(7950, ex.Message);
                            return false;
                        }
                        if (!string.IsNullOrEmpty(options.DocumentationFile)) {
                            try {
                                File.Copy(intermediateDocFile, options.DocumentationFile, true);
                            }
                            catch (IOException ex) {
                                er.Region = DomRegion.Empty;
                                er.Message(7952, ex.Message);
                                return false;
                            }
                        }
                    }

                    string script = string.Join("", js.Select(s => options.MinimizeScript ? OutputFormatter.FormatMinified(Minifier.Process(s)) : OutputFormatter.Format(s)));
                    try {
                        File.WriteAllText(outputScriptPath, script, settings.Encoding);
                    }
                    catch (IOException ex) {
                        er.Region = DomRegion.Empty;
                        er.Message(7951, ex.Message);
                        return false;
                    }
                    return true;
                }
                catch (Exception ex) {
                    er.Region = DomRegion.Empty;
                    er.InternalError(ex.ToString());
                    return false;
                }
                finally {
                    if (!options.AlreadyCompiled) {
                        try { File.Delete(intermediateAssemblyFile); } catch {}
                        try { File.Delete(intermediateDocFile); } catch {}
                    }
                }
            }
開發者ID:unintelligible,項目名稱:SaltarelleCompiler,代碼行數:85,代碼來源:CompilerDriver.cs

示例3: Compile

		public bool Compile(CompilerOptions options) {
			string intermediateAssemblyFile = Path.GetTempFileName(), intermediateDocFile = Path.GetTempFileName();
			var actualOut = Console.Out;
			var er = new ErrorReporterWrapper(_errorReporter, actualOut);
			try {
				Console.SetOut(new StringWriter());	// I don't trust the third-party libs to not generate spurious random messages, so make sure that any of those messages are suppressed.

				var settings = MapSettings(options, intermediateAssemblyFile, intermediateDocFile, er);
				if (er.HasErrors)
					return false;

				if (!options.AlreadyCompiled) {
					// Compile the assembly
					var ctx = new CompilerContext(settings, new ConvertingReportPrinter(er));
					var d = new Mono.CSharp.Driver(ctx);
					d.Compile();
					if (er.HasErrors)
						return false;
				}

				var references = LoadReferences(settings.AssemblyReferences, er);
				if (references == null)
					return false;

				PreparedCompilation compilation = PreparedCompilation.CreateCompilation(settings.AssemblyName, options.SourceFiles.Select(f => new SimpleSourceFile(f, settings.Encoding)), references.Select(r => r.Item1), options.DefineConstants, LoadResources(options.EmbeddedResources));

				IMethod entryPoint = FindEntryPoint(options, er, compilation);

				var container = new WindsorContainer();
				foreach (var plugin in TopologicalSortPlugins(references).Reverse())
					RegisterPlugin(container, plugin);

				container.Register(Component.For<IErrorReporter>().Instance(er),
				                   Component.For<CompilerOptions>().Instance(options),
				                   Component.For<ICompilation>().Instance(compilation.Compilation),
				                   Component.For<ICompiler>().ImplementedBy<Compiler.Compiler>()
				                  );

				container.Resolve<IMetadataImporter>().Prepare(compilation.Compilation.GetAllTypeDefinitions());

				var compiledTypes = container.Resolve<ICompiler>().Compile(compilation);

				foreach (var rewriter in container.ResolveAll<IJSTypeSystemRewriter>())
					compiledTypes = rewriter.Rewrite(compiledTypes);

				var invoker = new OOPEmulatorInvoker(container.Resolve<IOOPEmulator>(), container.Resolve<IMetadataImporter>(), container.Resolve<IErrorReporter>());

				var js = invoker.Process(compiledTypes.ToList(), entryPoint);
				js = container.Resolve<ILinker>().Process(js);

				if (er.HasErrors)
					return false;

				string outputAssemblyPath = !string.IsNullOrEmpty(options.OutputAssemblyPath) ? options.OutputAssemblyPath : Path.ChangeExtension(options.SourceFiles[0], ".dll");
				string outputScriptPath   = !string.IsNullOrEmpty(options.OutputScriptPath)   ? options.OutputScriptPath   : Path.ChangeExtension(options.SourceFiles[0], ".js");

				if (!options.AlreadyCompiled) {
					try {
						File.Copy(intermediateAssemblyFile, outputAssemblyPath, true);
					}
					catch (IOException ex) {
						er.Region = DomRegion.Empty;
						er.Message(Messages._7950, ex.Message);
						return false;
					}
					if (!string.IsNullOrEmpty(options.DocumentationFile)) {
						try {
							File.Copy(intermediateDocFile, options.DocumentationFile, true);
						}
						catch (IOException ex) {
							er.Region = DomRegion.Empty;
							er.Message(Messages._7952, ex.Message);
							return false;
						}
					}
				}

				if (options.MinimizeScript) {
					js = ((JsBlockStatement)Minifier.Process(JsStatement.Block(js))).Statements;
				}

				string script = options.MinimizeScript ? OutputFormatter.FormatMinified(js) : OutputFormatter.Format(js);
				try {
					File.WriteAllText(outputScriptPath, script, settings.Encoding);
				}
				catch (IOException ex) {
					er.Region = DomRegion.Empty;
					er.Message(Messages._7951, ex.Message);
					return false;
				}
				return true;
			}
			catch (Exception ex) {
				er.Region = DomRegion.Empty;
				er.InternalError(ex.ToString());
				return false;
			}
			finally {
				if (!options.AlreadyCompiled) {
					try { File.Delete(intermediateAssemblyFile); } catch {}
//.........這裏部分代碼省略.........
開發者ID:chenxustu1,項目名稱:SaltarelleCompiler,代碼行數:101,代碼來源:CompilerDriver.cs

示例4: Compile

            public bool Compile(CompilerOptions options, ErrorReporterWrapper er)
            {
                string intermediateAssemblyFile = Path.GetTempFileName(), intermediateDocFile = Path.GetTempFileName();
                try {
                    // Compile the assembly
                    var settings = MapSettings(options, intermediateAssemblyFile, intermediateDocFile, er);
                    if (er.HasErrors)
                        return false;

                    var ctx = new CompilerContext(settings, new ConvertingReportPrinter(er));
                    var d = new Mono.CSharp.Driver(ctx);
                    d.Compile();

                    if (er.HasErrors)
                        return false;

                    // Compile the script
                    var nc = new MetadataImporter.ScriptSharpMetadataImporter(options.MinimizeScript);
                    PreparedCompilation compilation = null;
                    var rtl = new ScriptSharpRuntimeLibrary(nc, tr => { var t = tr.Resolve(compilation.Compilation).GetDefinition(); return new JsTypeReferenceExpression(t.ParentAssembly, nc.GetTypeSemantics(t).Name); });
                    var compiler = new Saltarelle.Compiler.Compiler.Compiler(nc, rtl, er);

                    var references = LoadReferences(ctx.Settings.AssemblyReferences, er);
                    if (references == null)
                        return false;

                    compilation = compiler.CreateCompilation(options.SourceFiles.Select(f => new SimpleSourceFile(f)), references, options.DefineConstants);
                    var compiledTypes = compiler.Compile(compilation);

                    var js = new OOPEmulator.ScriptSharpOOPEmulator(nc, er).Rewrite(compiledTypes, compilation.Compilation);
                    js = new GlobalNamespaceReferenceImporter().ImportReferences(js);

                    if (er.HasErrors)
                        return false;

                    string outputAssemblyPath = !string.IsNullOrEmpty(options.OutputAssemblyPath) ? options.OutputAssemblyPath : Path.ChangeExtension(options.SourceFiles[0], ".dll");
                    string outputScriptPath   = !string.IsNullOrEmpty(options.OutputScriptPath)   ? options.OutputScriptPath   : Path.ChangeExtension(options.SourceFiles[0], ".js");

                    try {
                        File.Copy(intermediateAssemblyFile, outputAssemblyPath, true);
                    }
                    catch (IOException ex) {
                        er.Message(7950, null, TextLocation.Empty, ex.Message);
                        return false;
                    }
                    if (!string.IsNullOrEmpty(options.DocumentationFile)) {
                        try {
                            File.Copy(intermediateDocFile, options.DocumentationFile, true);
                        }
                        catch (IOException ex) {
                            er.Message(7952, null, TextLocation.Empty, ex.Message);
                            return false;
                        }
                    }

                    string script = string.Join("", js.Select(s => OutputFormatter.Format(s, allowIntermediates: false)));
                    try {
                        File.WriteAllText(outputScriptPath, script);
                    }
                    catch (IOException ex) {
                        er.Message(7951, null, TextLocation.Empty, ex.Message);
                        return false;
                    }
                    return true;
                }
                catch (Exception ex) {
                    er.InternalError(ex.ToString(), DomRegion.Empty);
                    return false;
                }
                finally {
                    try { File.Delete(intermediateAssemblyFile); } catch {}
                    try { File.Delete(intermediateDocFile); } catch {}
                }
            }
開發者ID:arnauddias,項目名稱:SaltarelleCompiler,代碼行數:74,代碼來源:CompilerDriver.cs


注:本文中的Mono.CSharp.Driver.Compile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。