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


C# Driver.CompilerDriver类代码示例

本文整理汇总了C#中Saltarelle.Compiler.Driver.CompilerDriver的典型用法代码示例。如果您正苦于以下问题:C# CompilerDriver类的具体用法?C# CompilerDriver怎么用?C# CompilerDriver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CompilerDriver类属于Saltarelle.Compiler.Driver命名空间,在下文中一共展示了CompilerDriver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ChangingTheWarningLevelWorks

        public void ChangingTheWarningLevelWorks()
        {
            UsingFiles(() => {
                File.WriteAllText(Path.GetFullPath("File.cs"), @"public class C1 { public void M() { var x = 0l; } }");
                var options = new CompilerOptions {
                    References         = { new Reference(Common.MscorlibPath) },
                    SourceFiles        = { Path.GetFullPath("File.cs") },
                    OutputAssemblyPath = Path.GetFullPath("Test.dll"),
                    OutputScriptPath   = Path.GetFullPath("Test.js"),
                };
                var er = new MockErrorReporter();
                var driver = new CompilerDriver(er);
                var result = driver.Compile(options, false);

                Assert.That(result, Is.True);
                Assert.That(er.AllMessages.Select(m => m.Code).ToList(), Is.EquivalentTo(new[] { 219, 78 }));
            }, "File.cs", "Test.dll", "Test.js");

            UsingFiles(() => {
                File.WriteAllText(Path.GetFullPath("File.cs"), @"public class C1 { public void M() { var x = 0l; } }");
                var options = new CompilerOptions {
                    References         = { new Reference(Common.MscorlibPath) },
                    SourceFiles        = { Path.GetFullPath("File.cs") },
                    OutputAssemblyPath = Path.GetFullPath("Test.dll"),
                    OutputScriptPath   = Path.GetFullPath("Test.js"),
                    WarningLevel       = 3,
                };
                var er = new MockErrorReporter();
                var driver = new CompilerDriver(er);
                var result = driver.Compile(options, false);

                Assert.That(result, Is.True);
                Assert.That(er.AllMessages.Select(m => m.Code), Is.EqualTo(new[] { 219 }));
            }, "File.cs", "Test.dll", "Test.js");
        }
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:35,代码来源:DriverTests.cs

示例2: CanCompileAsyncTaskGenericMethod

        public void CanCompileAsyncTaskGenericMethod()
        {
            UsingFiles(() => {
                File.WriteAllText(Path.GetFullPath("File1.cs"), @"
            using System.Threading.Tasks;
            public class C1 {
            public async Task<int> M() {
            var t = new Task(() => {});
            await t;
            return 0;
            }
            }");
                var options = new CompilerOptions {
                    References         = { new Reference(Common.MscorlibPath) },
                    SourceFiles        = { Path.GetFullPath("File1.cs") },
                    OutputAssemblyPath = Path.GetFullPath("Test.dll"),
                    OutputScriptPath   = Path.GetFullPath("Test.js")
                };
                var er = new MockErrorReporter();
                var driver = new CompilerDriver(er);
                var result = driver.Compile(options, false);

                Assert.That(result, Is.True);
                Assert.That(File.Exists(Path.GetFullPath("Test.dll")), Is.True, "Assembly should be written");
                Assert.That(File.Exists(Path.GetFullPath("Test.js")), Is.True, "Script should be written");
            }, "File1.cs", "Test.dll", "Test.js");
        }
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:27,代码来源:DriverTests.cs

示例3: CanCompileMscorlib

        public void CanCompileMscorlib()
        {
            var opts = ReadProject(Path.GetFullPath(@"..\..\..\Runtime\src\Libraries\CoreLib\CoreLib.csproj"));

            try {
                var er = new MockErrorReporter();
                var d = new CompilerDriver(er);
                bool result = d.Compile(opts, false);
                Assert.That(result, Is.True);
                Assert.That(er.AllMessages, Is.Empty);
            }
            finally {
                try { File.Delete(Path.GetFullPath("output.dll")); } catch {}
                try { File.Delete(Path.GetFullPath("output.js")); } catch {}
            }
        }
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:16,代码来源:EndToEndCompilation.cs

示例4: CanCompileProject

 public void CanCompileProject()
 {
     var opts = ReadProject(@"C:\Projects\EngineGit\Project\Search\Search.Client\Search.Client.csproj", @"C:\Projects\EngineGit\Project");
     opts.DefineConstants.Add("CLIENT");
     try {
         var er = new MockErrorReporter();
         var d = new CompilerDriver(er);
         bool result = d.Compile(opts, false);
         Assert.That(result, Is.True);
         Assert.That(er.AllMessages, Is.Empty);
     }
     finally {
         try { File.Delete(Path.GetFullPath("output.dll")); } catch {}
         try { File.Delete(Path.GetFullPath("output.js")); } catch {}
     }
 }
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:16,代码来源:EndToEndCompilation.cs

示例5: CanInitializeListWithCollectionInitializer

        public void CanInitializeListWithCollectionInitializer()
        {
            UsingFiles(() => {
                File.WriteAllText(Path.GetFullPath("Test.cs"), @"using System.Collections.Generic; public class C1 { public void M() { var l = new List<int> { 1 }; } }");
                var options = new CompilerOptions {
                    References         = { new Reference(Common.MscorlibPath) },
                    SourceFiles        = { Path.GetFullPath("Test.cs") },
                    OutputAssemblyPath = Path.GetFullPath("Test.dll"),
                    OutputScriptPath   = Path.GetFullPath("Test.js")
                };
                var er = new MockErrorReporter();
                var driver = new CompilerDriver(er);
                var result = driver.Compile(options, false);

                Assert.That(result, Is.True, "Compilation failed with " + string.Join(Environment.NewLine, er.AllMessagesText));
            }, "File1.cs", "Test.dll", "Test.js");
        }
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:17,代码来源:DriverTests.cs

示例6: SimpleCompilationWorks

		public void SimpleCompilationWorks() {
			UsingFiles(() => {
				File.WriteAllText(Path.GetFullPath("File1.cs"), @"using System.Collections; public class C1 { public JsDictionary M() { return null; } }");
				File.WriteAllText(Path.GetFullPath("File2.cs"), @"using System.Collections; public class C2 { public JsDictionary M() { return null; } }");
				var options = new CompilerOptions {
					References         = { new Reference(Common.MscorlibPath) },
					SourceFiles        = { Path.GetFullPath("File1.cs"), Path.GetFullPath("File2.cs") },
					OutputAssemblyPath = Path.GetFullPath("Test.dll"),
					OutputScriptPath   = Path.GetFullPath("Test.js")
				};
				var driver = new CompilerDriver(new MockErrorReporter());
				var result = driver.Compile(options, null);

				Assert.That(result, Is.True);
				Assert.That(File.Exists(Path.GetFullPath("Test.dll")), Is.True, "Assembly should be written");
				Assert.That(File.Exists(Path.GetFullPath("Test.js")), Is.True, "Script should be written");
			}, "File1.cs", "File2.cs", "Test.dll", "Test.js");
		}
开发者ID:pdavis68,项目名称:SaltarelleCompiler,代码行数:18,代码来源:DriverTests.cs

示例7: CanCompileProject

		//[Test, Ignore("Debugging purposes")]
		public void CanCompileProject() {
			var opts = ReadProject(Path.GetFullPath(@"..\..\..\Runtime\CoreLib.TestScript\CoreLib.TestScript.csproj"));
			opts.References.Clear();
			opts.References.Add(new Reference(Common.MscorlibPath));
			opts.References.Add(new Reference(Path.GetFullPath(@"../../../Runtime/QUnit/bin/Saltarelle.QUnit.dll")));
			opts.AlreadyCompiled = true;
			try {
				var er = new MockErrorReporter();
				var d = new CompilerDriver(er);
				bool result = d.Compile(opts, null);
				Assert.That(result, Is.True);
				Assert.That(er.AllMessages, Is.Empty);
			}
			finally {
				try { File.Delete(Path.GetFullPath("output.dll")); } catch {}
				try { File.Delete(Path.GetFullPath("output.js")); } catch {}
			}
		}
开发者ID:pdavis68,项目名称:SaltarelleCompiler,代码行数:19,代码来源:EndToEndCompilation.cs

示例8: CanCompileLockStatement

        public void CanCompileLockStatement()
        {
            UsingFiles(() => {
                File.WriteAllText(Path.GetFullPath("File1.cs"), @"using System.Collections.Generic; public class C1 { public void M() { lock (new object()) {} } }");
                var options = new CompilerOptions {
                    References         = { new Reference(Common.MscorlibPath) },
                    SourceFiles        = { Path.GetFullPath("File1.cs") },
                    OutputAssemblyPath = Path.GetFullPath("Test.dll"),
                    OutputScriptPath   = Path.GetFullPath("Test.js")
                };
                var driver = new CompilerDriver(new MockErrorReporter());
                var result = driver.Compile(options, false);

                Assert.That(result, Is.True);
                Assert.That(File.Exists(Path.GetFullPath("Test.dll")), Is.True, "Assembly should be written");
                Assert.That(File.Exists(Path.GetFullPath("Test.js")), Is.True, "Script should be written");
            }, "File1.cs", "Test.dll", "Test.js");
        }
开发者ID:jack128,项目名称:SaltarelleCompiler,代码行数:18,代码来源:DriverTests.cs

示例9: AssemblyNameIsCorrectInTheGeneratedScript

		public void AssemblyNameIsCorrectInTheGeneratedScript() {
			UsingFiles(() => {
				File.WriteAllText(Path.GetFullPath("File1.cs"), @"using System.Collections; public class C1 { public JsDictionary M() { return null; } }");
				File.WriteAllText(Path.GetFullPath("File2.cs"), @"using System.Collections; public class C2 { public JsDictionary M() { return null; } }");
				var options = new CompilerOptions {
					References         = { new Reference(Common.MscorlibPath) },
					SourceFiles        = { Path.GetFullPath("File1.cs"), Path.GetFullPath("File2.cs") },
					OutputAssemblyPath = Path.GetFullPath("Test.Assembly.dll"),
					OutputScriptPath   = Path.GetFullPath("Test.js")
				};
				var driver = new CompilerDriver(new MockErrorReporter());
				var result = driver.Compile(options);

				Assert.That(result, Is.True);
				var text = File.ReadAllText(Path.GetFullPath("Test.js"));
				Assert.That(text.Contains("ss.initAssembly($asm, 'Test.Assembly')"));    // Verify that the symbol was passed to the script compiler.
			}, "File1.cs", "File2.cs", "Test.Assembly.dll", "Test.js");
		}
开发者ID:chenxustu1,项目名称:SaltarelleCompiler,代码行数:18,代码来源:DriverTests.cs

示例10: CompileErrorsAreReportedAndCauseFilesNotToBeGenerated

		public void CompileErrorsAreReportedAndCauseFilesNotToBeGenerated() {
			UsingFiles(() => {
				File.WriteAllText(Path.GetFullPath("File.cs"), @"public class C1 { public void M() { var x = y; } }");
				var options = new CompilerOptions {
					References         = { new Reference(Common.MscorlibPath) },
					SourceFiles        = { Path.GetFullPath("File.cs") },
					OutputAssemblyPath = Path.GetFullPath("Test.dll"),
					OutputScriptPath   = Path.GetFullPath("Test.js")
				};
				var er = new MockErrorReporter();
				var driver = new CompilerDriver(er);
				var result = driver.Compile(options, null);

				Assert.That(result, Is.False);
				Assert.That(er.AllMessages.Any(m => m.Severity == MessageSeverity.Error && m.Code == 103 && m.Region.FileName == Path.GetFullPath("File.cs") && m.Region.Begin == new TextLocation(1, 45) && m.Format != null && m.Args.Length == 0));
				Assert.That(File.Exists(Path.GetFullPath("Test.dll")), Is.False, "Assembly should not be written");
				Assert.That(File.Exists(Path.GetFullPath("Test.js")), Is.False, "Script should not be written");
			}, "File.cs", "Test.dll", "Test.js");
		}
开发者ID:pdavis68,项目名称:SaltarelleCompiler,代码行数:19,代码来源:DriverTests.cs

示例11: CanCompileLinqJSTests

        public void CanCompileLinqJSTests()
        {
            var opts = ReadProject(Path.GetFullPath(@"..\..\..\Runtime\src\Tests\LinqJSTests\LinqJSTests.csproj"));
            opts.References.Clear();
            opts.References.Add(new Reference(Common.MscorlibPath));
            opts.References.Add(new Reference(Path.GetFullPath(@"..\..\..\Runtime\bin\Script.Linq.dll")));

            try {
                var er = new MockErrorReporter();
                var d = new CompilerDriver(er);
                bool result = d.Compile(opts, false);
                Assert.That(result, Is.True);
                Assert.That(er.AllMessages, Is.Empty);
            }
            finally {
                try { File.Delete(Path.GetFullPath("output.dll")); } catch {}
                try { File.Delete(Path.GetFullPath("output.js")); } catch {}
            }
        }
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:19,代码来源:EndToEndCompilation.cs

示例12: AssemblyThatCanNotBeLocatedCausesError7997

        public void AssemblyThatCanNotBeLocatedCausesError7997()
        {
            UsingFiles(() => {
                File.WriteAllText(Path.GetFullPath("File.cs"), @"class Class1 { public void M() {} }");
                var options = new CompilerOptions {
                    References         = { new Reference(Common.MscorlibPath), new Reference("MyNonexistentAssembly") },
                    SourceFiles        = { Path.GetFullPath("File.cs") },
                    OutputAssemblyPath = Path.GetFullPath("Test.dll"),
                    OutputScriptPath   = Path.GetFullPath("Test.js"),
                    MinimizeScript     = false,
                };
                var er = new MockErrorReporter();
                var driver = new CompilerDriver(er);
                var result = driver.Compile(options, false);

                Assert.That(er.AllMessages, Has.Count.EqualTo(1));
                Assert.That(er.AllMessages.Any(m => m.Code == 7997 && (string)m.Args[0] == "MyNonexistentAssembly"));

                Assert.That(result, Is.False);
                Assert.That(File.Exists(Path.GetFullPath("Test.dll")), Is.False);
            }, "File.cs", "Test.dll", "Test.js");
        }
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:22,代码来源:DriverTests.cs

示例13: TheOutputFileNamesAreTakenFromTheFirstSourceFileIfNotSpecified

        public void TheOutputFileNamesAreTakenFromTheFirstSourceFileIfNotSpecified()
        {
            UsingFiles(() => {
                File.WriteAllText(Path.GetFullPath("FirstFile.cs"), @"class C1 { public void M() {} }");
                File.WriteAllText(Path.GetFullPath("SecondFile.cs"), @"class C2 { public void M() {} }");
                var options = new CompilerOptions {
                    References  = { new Reference(Common.MscorlibPath) },
                    SourceFiles = { Path.GetFullPath("FirstFile.cs"), Path.GetFullPath("SecondFile.cs") },
                };
                var er = new MockErrorReporter();
                var driver = new CompilerDriver(er);
                var result = driver.Compile(options, false);

                Assert.That(result, Is.True);
                Assert.That(File.Exists(Path.GetFullPath("FirstFile.dll")), Is.True);
                Assert.That(File.Exists(Path.GetFullPath("FirstFile.js")), Is.True);

                var asm = AssemblyDefinition.ReadAssembly(Path.GetFullPath("FirstFile.dll"));
                Assert.That(asm.Name.Name, Is.EqualTo("FirstFile"));
            }, "FirstFile.cs", "SecondFile.cs", "FirstFile.dll", "FirstFile.js");
        }
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:21,代码来源:DriverTests.cs

示例14: TheAssemblyNameIsCorrect

        public void TheAssemblyNameIsCorrect()
        {
            UsingFiles(() => {
                File.WriteAllText(Path.GetFullPath("File.cs"), @"class Class1 { public void M() {} }");
                var options = new CompilerOptions {
                    References         = { new Reference(Common.MscorlibPath) },
                    SourceFiles        = { Path.GetFullPath("File.cs") },
                    OutputAssemblyPath = Path.GetFullPath("MyOutputAssembly.dll"),
                    OutputScriptPath   = Path.GetFullPath("Test.js"),
                    DocumentationFile  = Path.GetFullPath("Test.xml"),
                    MinimizeScript     = false,
                };
                var er = new MockErrorReporter();
                var driver = new CompilerDriver(er);
                var result = driver.Compile(options, false);

                Assert.That(result, Is.True);
                Assert.That(File.Exists(Path.GetFullPath("Test.xml")), Is.True);
                string doc = File.ReadAllText(Path.GetFullPath("Test.xml"));
                Assert.That(XDocument.Parse(doc).XPathSelectElement("/doc/assembly/name").Value, Is.EqualTo("MyOutputAssembly"));

                var asm = AssemblyDefinition.ReadAssembly(Path.GetFullPath("MyOutputAssembly.dll"));
                Assert.That(asm.Name.Name, Is.EqualTo("MyOutputAssembly"));
            }, "File.cs", "MyOutputAssembly.dll", "Test.js", "Test.xml");
        }
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:25,代码来源:DriverTests.cs

示例15: SpecificWarningsNotAsErrorsWorks

        public void SpecificWarningsNotAsErrorsWorks()
        {
            UsingFiles(() => {
                File.WriteAllText(Path.GetFullPath("File.cs"), @"public class C1 { public void M() { var x = 0; } }");
                var options = new CompilerOptions {
                    References            = { new Reference(Common.MscorlibPath) },
                    SourceFiles           = { Path.GetFullPath("File.cs") },
                    OutputAssemblyPath    = Path.GetFullPath("Test.dll"),
                    OutputScriptPath      = Path.GetFullPath("Test.js"),
                    TreatWarningsAsErrors = true,
                    WarningsNotAsErrors   = { 219 }
                };
                var er = new MockErrorReporter();
                var driver = new CompilerDriver(er);
                var result = driver.Compile(options, false);

                Assert.That(result, Is.True);
                Assert.That(er.AllMessages.Any(m => m.Severity == MessageSeverity.Warning && m.Code == 219 && m.Region.FileName == Path.GetFullPath("File.cs") && m.Region.Begin == new TextLocation(1, 41) && m.Format != null && m.Args.Length == 0));
                Assert.That(File.Exists(Path.GetFullPath("Test.dll")), Is.True, "Assembly should be written");
                Assert.That(File.Exists(Path.GetFullPath("Test.js")), Is.True, "Script should be written");
            }, "File.cs", "Test.dll", "Test.js");
        }
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:22,代码来源:DriverTests.cs


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