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


C# VBCodeProvider.CreateCompiler方法代码示例

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


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

示例1: CreateCompiler_ReturnsSame

        public void CreateCompiler_ReturnsSame()
        {
            VBCodeProvider provider = new VBCodeProvider();
#pragma warning disable 0618
            Assert.Same(provider.CreateCompiler(), provider.CreateCompiler());
#pragma warning restore 0618
        }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:VBCodeProviderTests.cs

示例2: Deny_Unrestricted

		public void Deny_Unrestricted ()
		{
			VBCodeProvider vbprov = new VBCodeProvider ();
			Assert.AreEqual ("vb", vbprov.FileExtension, "FileExtension");
			Assert.AreEqual (LanguageOptions.CaseInsensitive, vbprov.LanguageOptions, "LanguageOptions");
			Assert.IsNotNull (vbprov.CreateCompiler (), "CreateCompiler");
			Assert.IsNotNull (vbprov.CreateGenerator (), "CreateGenerator");
			try {
				Assert.IsNotNull (vbprov.GetConverter (typeof (string)), "GetConverter");
			}
			catch (NotImplementedException) {
				// mono
			}
#if NET_2_0
			CodeTypeMember ctm = new CodeTypeMember ();
			StringWriter sw = new StringWriter ();
			CodeGeneratorOptions cgo = new CodeGeneratorOptions ();
			try {
				vbprov.GenerateCodeFromMember (ctm, sw, cgo);
			}
			catch (NotImplementedException) {
				// mono
			}
#endif
		}
开发者ID:nlhepler,项目名称:mono,代码行数:25,代码来源:VBCodeProviderCas.cs

示例3: Ctor_IDictionaryStringString

        public void Ctor_IDictionaryStringString(IDictionary<string, string> providerOptions)
        {
            VBCodeProvider provider = new VBCodeProvider();
#pragma warning disable 0618
            Assert.NotNull(provider.CreateGenerator());
            Assert.Same(provider.CreateGenerator(), provider.CreateCompiler());
#pragma warning restore 0618
        }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:VBCodeProviderTests.cs

示例4: Ctor_Default

        public void Ctor_Default()
        {
            VBCodeProvider provider = new VBCodeProvider();
#pragma warning disable 0618
            Assert.NotNull(provider.CreateGenerator());
            Assert.Same(provider.CreateGenerator(), provider.CreateCompiler());
#pragma warning restore 0618
        }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:VBCodeProviderTests.cs

示例5: TestUtilities

		static TestUtilities()
		{
			cSharpCompiler = new CSharpCodeProvider();
			compiler = cSharpCompiler.CreateCompiler();
			compileParameters = new CompilerParameters();

			vbCompilerProvider = new VBCodeProvider();
			vbCompiler = vbCompilerProvider.CreateCompiler();
			vbCompileParameters = new CompilerParameters();
		}
开发者ID:SteGriff,项目名称:NCover,代码行数:10,代码来源:TestUtilities.cs

示例6: CompileVBScripts

        private static CompilerResults CompileVBScripts(ICollection fileColl,
														string assemblyFile,
														LibraryConfig libConfig,
														bool debug)
        {
            VBCodeProvider provider = new VBCodeProvider();
            ICodeCompiler compiler = provider.CreateCompiler();

            string[] files = new string[fileColl.Count];
            fileColl.CopyTo(files, 0);

            Console.Write("{0}[VB,{1}", libConfig.Name, files.Length);

            CompilerResults results = compiler.CompileAssemblyFromFileBatch( new CompilerParameters( GetReferenceAssemblies(), assemblyFile, true ), files );

            m_AdditionalReferences.Add(assemblyFile);

            if ( results.Errors.Count > 0 )
            {
                int errorCount = 0, warningCount = 0;

                foreach ( CompilerError e in results.Errors )
                {
                    if ( e.IsWarning )
                        ++warningCount;
                    else
                        ++errorCount;
                }

                Console.WriteLine();
                if ( errorCount > 0 )
                    Console.WriteLine( "failed ({0} errors, {1} warnings)", errorCount, warningCount );
                else
                    Console.WriteLine( "done ({0} errors, {1} warnings)", errorCount, warningCount );

                foreach ( CompilerError e in results.Errors )
                {
                    Console.WriteLine( " - {0}: {1}: {2}: (line {3}, column {4}) {5}", e.IsWarning ? "Warning" : "Error", e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText );
                }
            }
            else
            {
                Console.Write("] ");
            }

            return results;
        }
开发者ID:BackupTheBerlios,项目名称:sunuo-svn,代码行数:47,代码来源:ScriptCompiler.cs

示例7: CompileRunningVB

        private void CompileRunningVB()
        {
            string name2 = name;
            if (name == "") name2 = "DotNetProcessing.Running";
            else name2 = name2 + "Sketch";

            // Generamos DotNetProcessing.Running.dll
            VBCodeProvider vbCompiler;
            ICodeCompiler iCodeCompiler;
            CompilerParameters compilerParams;
            CompilerResults cr;

            vbCompiler = new VBCodeProvider();
            iCodeCompiler = vbCompiler.CreateCompiler();

            compilerParams = new CompilerParameters();
            compilerParams.OutputAssembly = apppath + name2 + ".dll";
            compilerParams.ReferencedAssemblies.Add("System.dll");
            compilerParams.ReferencedAssemblies.Add("mscorlib.dll");
            compilerParams.ReferencedAssemblies.Add("System.Core.dll");
            compilerParams.ReferencedAssemblies.Add("System.Drawing.dll");
            compilerParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
            compilerParams.ReferencedAssemblies.Add(apppath + "DotNetProcessing.Kernel.dll");
            compilerParams.ReferencedAssemblies.Add(apppath + "DotNetProcessing.AbstractRunning.dll");
            compilerParams.GenerateExecutable = false;
            cr = iCodeCompiler.CompileAssemblyFromFile(compilerParams, apppath + "DotNetProcessing.Running" + sep + "RunnerCopy.vb");

            if( cr.Errors.Count > 0 )
            {
                string er = "";
                for( int i=0; i<cr.Errors.Count; i++ )
                {
                    StreamReader srerrors = File.OpenText(apppath + "DotNetProcessing.Running" + sep + "RunnerCopy.vb");
                    for (int j=0; j<cr.Errors[i].Line-1; j++) srerrors.ReadLine();
                    er = er + "ERROR:\t" + cr.Errors[i].ErrorText + "\r\n" + "LINE:\t" + srerrors.ReadLine().Trim() + "\r\nCOLUMN:\t" + cr.Errors[i].Column + "\r\n\r\n";
                    srerrors.Close();
                }
                try
                {
                DelFileWrapper(apppath + "Input.pde");
                DelFileWrapper(apppath + "DotNetProcessing.Running" + sep + "RunnerCopy.vb");
                }
                catch
                {}
                throw new DNPParseException(er);
            }
        }
开发者ID:exaphaser,项目名称:ExaPhaser-Processing,代码行数:47,代码来源:Parser.cs

示例8: CompileVBScripts

		private static CompilerResults CompileVBScripts(ICollection fileColl,
														string assemblyFile,
														Config.Library libConfig,
														bool debug) {
			VBCodeProvider provider = new VBCodeProvider();
			ICodeCompiler compiler = provider.CreateCompiler();

			string[] files = new string[fileColl.Count];
			fileColl.CopyTo(files, 0);

			log.InfoFormat("Compiling library {0}, {1} C# sources",
						   libConfig.Name, files.Length);

			CompilerResults results = compiler.CompileAssemblyFromFileBatch( new CompilerParameters( GetReferenceAssemblies(), assemblyFile, true ), files );

			m_AdditionalReferences.Add(assemblyFile);

			if ( results.Errors.Count > 0 )
			{
				int errorCount = 0, warningCount = 0;

				foreach ( CompilerError e in results.Errors )
				{
					if ( e.IsWarning )
						++warningCount;
					else
						++errorCount;
				}

				if ( errorCount > 0 )
					log.ErrorFormat("Compilation failed ({0} errors, {1} warnings)",
									errorCount, warningCount);
				else
					log.InfoFormat("Compilation complete ({0} warnings)", warningCount);

				foreach ( CompilerError e in results.Errors )
				{
					String msg = String.Format("{0}: {1}: (line {2}, column {3}) {4}",
											   e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText);
					if (e.IsWarning)
						log.Warn(msg);
					else
						log.Error(msg);
				}
			}
			else
			{
				log.Info("Compilation complete");
			}

			return results;
		}
开发者ID:kamronbatman,项目名称:DefianceUO-Pre1.10,代码行数:52,代码来源:ScriptCompiler.cs

示例9: Main

        static void Main(string[] args)
        {
            // Prompt for target language.
            Console.Write("Do you want to generate C# or VB .NET code? ");
            syntaxTarget = Console.ReadLine();

            // Get ICodeGenerator interface.
            switch(syntaxTarget.ToUpper())
            {
                case "C#":
                case "CSharp":
                case "CS":
                    syntaxTarget = "cs";
                    CSharpCodeProvider cdp = new CSharpCodeProvider();
                    itfCG = cdp.CreateGenerator();
                    itfCC = cdp.CreateCompiler();
                break;
                case "VB .NET":
                case "VB.NET":
                case "VB":
                    syntaxTarget = "vb";
                    VBCodeProvider vbdp = new VBCodeProvider();
                    itfCG = vbdp.CreateGenerator();
                    itfCC = vbdp.CreateCompiler();
                break;
                default:
                    Console.WriteLine("Sorry...can't do it...");
                    syntaxTarget = null;
                break;
            }

            // Only proceed if they picked a valid language
            // supported by System.CodeDOM.
            if(syntaxTarget != null)
            {
                // Now create the file and generate the code!
                TextWriter txtWriter = CreateFile(syntaxTarget);
                PopulateNamespace(itfCG, txtWriter);
                txtWriter.Close();
                Console.WriteLine("Done!");

                // Now compile the code into a .NET DLL.
                Console.WriteLine("Compiling code...");
                CompileCode(itfCC, syntaxTarget);

                // Now launch the application!
                Console.Write("Enter your message: ");
                string msg = Console.ReadLine();
                LoadAndRunAsm(msg);
                Console.WriteLine("Thanks for playing...");
            }
        }
开发者ID:rojac07,项目名称:COM,代码行数:52,代码来源:HelloWorldGenApp.cs

示例10: CompileAssemblyFromDomBatch

			public string CompileAssemblyFromDomBatch (string tempDir)
			{
				CompilerParameters options = new CompilerParameters ();
				options.GenerateExecutable = false;
				options.GenerateInMemory = false;
				options.TempFiles = new TempFileCollection (tempDir);

				VBCodeProvider codeProvider = new VBCodeProvider ();
				ICodeCompiler compiler = codeProvider.CreateCompiler ();
				CompilerResults results = compiler.CompileAssemblyFromDomBatch (options, new CodeCompileUnit[] { new CodeCompileUnit (), new CodeCompileUnit () });

				// verify compilation was successful
				AssertCompileResults (results, true);

				if (results.CompiledAssembly.Location.Length == 0)
					throw new Exception ("Location should not be empty string");
				if (results.PathToAssembly == null)
					throw new Exception ("PathToAssembly should not be null");

				return results.PathToAssembly;
			}
开发者ID:Profit0004,项目名称:mono,代码行数:21,代码来源:VBCodeProviderTest.cs

示例11: CompileAssemblyFromDom

			public string CompileAssemblyFromDom (string tempDir)
			{
				CompilerParameters options = new CompilerParameters ();
				options.GenerateExecutable = false;
				options.GenerateInMemory = false;
				options.TempFiles = new TempFileCollection (tempDir);

				VBCodeProvider codeProvider = new VBCodeProvider ();
				ICodeCompiler compiler = codeProvider.CreateCompiler ();
				CompilerResults results = compiler.CompileAssemblyFromDom (options, new CodeCompileUnit ());

				// verify compilation was successful
				AssertCompileResults (results, true);

				Assert.IsTrue (results.CompiledAssembly.Location.Length != 0,
					"Location should not be empty string");
				Assert.IsNotNull (results.PathToAssembly, "PathToAssembly should not be null");

				return results.PathToAssembly;
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:20,代码来源:VBCodeProviderTest.cs

示例12: CompileVBScripts

		private static CompilerResults CompileVBScripts(bool debug)
		{
			VBCodeProvider provider = new VBCodeProvider();
			ICodeCompiler compiler = provider.CreateCompiler();

			Console.Write("Scripts: Compiling VB.net scripts...");
			string[] files = GetScripts("*.vb");

			if (files.Length == 0)
			{
				Console.WriteLine("no files found.");
				return null;
			}

			string path = GetUnusedPath("Scripts.VB");

			CompilerResults results = compiler.CompileAssemblyFromFileBatch(new CompilerParameters(GetReferenceAssemblies(), path, true), files);

			m_AdditionalReferences.Add(path);

			if (results.Errors.Count > 0)
			{
				int errorCount = 0, warningCount = 0;

				foreach (CompilerError e in results.Errors)
				{
					if (e.IsWarning)
						++warningCount;
					else
						++errorCount;
				}

				if (errorCount > 0)
					Console.WriteLine("failed ({0} errors, {1} warnings)", errorCount, warningCount);
				else
					Console.WriteLine("done ({0} errors, {1} warnings)", errorCount, warningCount);

				foreach (CompilerError e in results.Errors)
				{
					Console.WriteLine(" - {0}: {1}: {2}: (line {3}, column {4}) {5}", e.IsWarning ? "Warning" : "Error", e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText);
				}
			}
			else
			{
				Console.WriteLine("done (0 errors, 0 warnings)");
			}

			return results;
		}
开发者ID:zerodowned,项目名称:angelisland,代码行数:49,代码来源:ScriptCompiler.cs


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