• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# VisualBasic.VBCodeProvider类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Compile

        void Compile(string Code, string Path, bool FormProgram, string MainClass)
        {
            Dictionary<string, string> providerOptions = new Dictionary<string, string>();
            providerOptions.Add("CompilerVersion", "v2.0");
            VBCodeProvider CodeProvider = new VBCodeProvider(providerOptions);
            CompilerParameters Parameters = new CompilerParameters();
            Parameters.GenerateExecutable = true;
            Parameters.OutputAssembly = Path;
            if (FormProgram) Parameters.CompilerOptions = "/target:winexe";
            Parameters.MainClass = MainClass;
            Parameters.IncludeDebugInformation = false;
            Parameters.ReferencedAssemblies.Add("System.dll");
            Parameters.ReferencedAssemblies.Add("System.Data.dll");
            Parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
            Parameters.ReferencedAssemblies.Add("System.Drawing.dll");
            Parameters.ReferencedAssemblies.Add("System.XML.dll");

            CompilerResults Results = CodeProvider.CompileAssemblyFromSource(Parameters, Code);
            if (Results.Errors.Count > 0)
            {
                foreach (CompilerError E in Results.Errors)
                {
                    MessageBox.Show(E.ErrorText);
                }
            }
        }
开发者ID:Methh,项目名称:CooLogger,代码行数:26,代码来源:SMTPTab.cs


示例2: Create

        /// <summary>
        ///     Creates a code DOM provider appropriate for the specified script language.
        /// </summary>
        /// <param name="scriptLanguage">The script language.</param>
        /// <param name="compilerVersion">The compiler version.</param>
        /// <returns>A code DOM provider.</returns>
        public static CodeDomProvider Create(ScriptLanguage scriptLanguage, string compilerVersion)
        {
            if (compilerVersion == null)
            {
                throw new ArgumentNullException("compilerVersion");
            }
            else if (string.IsNullOrWhiteSpace(compilerVersion))
            {
                throw new ArgumentException(InternalExceptionStrings.ArgumentException_EmptyOrWhitespaceString, "compilerVersion");
            }

            CodeDomProvider instance;

            Dictionary<string, string> providerOptions =
                new Dictionary<string, string>()
                    {
                        { "CompilerVersion", compilerVersion }
                    };

            if (scriptLanguage == ScriptLanguage.CSharp)
            {
                instance = new CSharpCodeProvider(providerOptions);
            }
            else if (scriptLanguage == ScriptLanguage.VisualBasic)
            {
                instance = new VBCodeProvider(providerOptions);
            }
            else
            {
                throw new InvalidOperationException(InvalidOperationException_UnsupportedLanguage);
            }

            return instance;
        }
开发者ID:valipan,项目名称:Subspace.TextTemplating,代码行数:40,代码来源:CodeDomProviderFactory.cs


示例3: Compile

 public override bool Compile(string queryText, QueryCore query, TempFileRef dataContextAssembly)
 {
     bool flag;
     StringBuilder builder = new StringBuilder(this.GetHeader(query));
     base.LineOffset = builder.ToString().Count<char>(c => c == '\n');
     builder.AppendLine(Regex.Replace(queryText.Trim(), "(?<!\r)\n", "\r\n"));
     builder.Append(this.GetFooter(query));
     string str = "v4.0";
     Dictionary<string, string> providerOptions = new Dictionary<string, string>();
     providerOptions.Add("CompilerVersion", str);
     VBCodeProvider codeProvider = new VBCodeProvider(providerOptions);
     if ((!(flag = base.Compile(codeProvider, builder.ToString(), dataContextAssembly, query.QueryKind, this.GetCompilerOptions(query))) && (query.QueryKind == QueryLanguage.VBExpression)) && (base.ErrorMessage == ") expected"))
     {
         base.ErrorMessage = ") or end of expression expected";
         return flag;
     }
     if (!(flag || !base.ErrorMessage.ToLowerInvariant().Contains("predicatebuilder")))
     {
         base.ErrorMessage = base.ErrorMessage + QueryCompiler.PredicateBuilderMessage;
         return flag;
     }
     if (!(((flag || (query.QueryKind != QueryLanguage.VBStatements)) || !(base.ErrorMessage == "Expression is not a method.")) || query.Source.TrimStart(new char[0]).StartsWith("dim", StringComparison.OrdinalIgnoreCase)))
     {
         base.ErrorMessage = base.ErrorMessage + "\r\n(Try setting the query language to 'VB Expression' rather than 'VB Statements')";
         return flag;
     }
     if ((!flag && (query.QueryKind == QueryLanguage.VBExpression)) && (base.ErrorMessage == "Expression expected."))
     {
         base.ErrorMessage = base.ErrorMessage + "\r\n(Set the query language to 'VB Statement(s)' for a statement-based code)";
     }
     return flag;
 }
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:32,代码来源:VBQueryCompiler.cs


示例4: Compile

 public CompilerResults Compile()
 {
     Dictionary<string, string> dictionary = new Dictionary<string, string>();
     dictionary.Add("CompilerVersion", "v4.0");
     CodeDomProvider codeDomProvider;
     switch (this.codeLang)
     {
         case CodeLang.CSharp:
             codeDomProvider = new CSharpCodeProvider(dictionary);
             break;
         case CodeLang.VisualBasic:
             codeDomProvider = new VBCodeProvider(dictionary);
             break;
         default:
             throw new NotSupportedException(string.Format("Not supported code language - {0}", this.codeLang));
     }
     foreach (string reference in this.references)
         this.parameters.ReferencedAssemblies.Add(reference);
     if (this.codeLang == CodeLang.VisualBasic)
     {
         foreach (object obj in new List<string>()
         {  
             "FreeQuant.FIX", 
             "FreeQuant.Instruments", 
             "FreeQuant.Series", 
             "FreeQuant.Charting" 
         })
             this.parameters.ReferencedAssemblies.Add(Path.Combine(Framework.Installation.BinDir.FullName, string.Format("{0}.dll", obj)));
     }
     return codeDomProvider.CompileAssemblyFromFile(this.parameters, this.filenames.ToArray());
 }
开发者ID:smther,项目名称:FreeOQ,代码行数:31,代码来源:CompilingServices.cs


示例5: CompileToAssembly

        /// <summary>
        /// Compiles the source to assembly.
        /// </summary>
        /// <param name="script">The SharpScript.</param>
        /// <returns>Assembly.</returns>
        public static Assembly CompileToAssembly(VBScript script)
        {
            var cdProvider = new VBCodeProvider();
            var param = new CompilerParameters();
            param.ReferencedAssemblies.Add("System.dll");
            param.ReferencedAssemblies.Add("Sharpex2D.dll");
            param.ReferencedAssemblies.Add(Application.ExecutablePath);
            param.GenerateExecutable = false;

            CompilerResults result = cdProvider.CompileAssemblyFromSource(param, script.Content);

            bool flag = false;

            foreach (CompilerError error in result.Errors)
            {
                if (error.IsWarning)
                {
                    Logger.Warn("{0} -> {1} (Line {2})", script.Guid, error.ErrorText, error.Line);
                }
                else
                {
                    Logger.Critical("{0} -> {1} (Line {2})", script.Guid, error.ErrorText, error.Line);
                    flag = true;
                }
            }

            if (flag)
            {
                throw new ScriptException("Critical error while compiling script.");
            }

            return result.CompiledAssembly;
        }
开发者ID:ThuCommix,项目名称:Sharpex2D,代码行数:38,代码来源:VBScriptCompiler.cs


示例6: 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


示例7: 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


示例8: Execute

 /// <summary>
 ///     Main executor function.
 /// </summary>
 /// <returns>A string of generated VB.net code.</returns>
 public string Execute()
 {
     using (var codeProvider = new VBCodeProvider())
     {
         return CodeUnitToLanguage(codeProvider);
     }
 }
开发者ID:aeagle,项目名称:json-schema-2-poco,代码行数:11,代码来源:CodeCompileUnitToVisualBasic.cs


示例9: gen

        public void gen(string output, string source)
        {
            ICodeCompiler Compiler = new VBCodeProvider().CreateCompiler();
            var Parameters = new CompilerParameters();
            CompilerResults cResults;
            Parameters.GenerateExecutable = true;
            Parameters.OutputAssembly = output;
            Parameters.ReferencedAssemblies.Add("System.dll");
            Parameters.ReferencedAssemblies.Add("System.Data.dll");
            Parameters.ReferencedAssemblies.Add("System.Drawing.dll");
            Parameters.ReferencedAssemblies.Add("System.Design.dll");
            Parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
            Parameters.ReferencedAssemblies.Add("System.XML.dll");
            Parameters.ReferencedAssemblies.Add("System.Management.dll");
            Parameters.ReferencedAssemblies.Add("System.Management.dll");
            if (CheckBox26.Checked & (source == this._source))
                Parameters.EmbeddedResources.Add(Application.StartupPath + "\\Process.resources");

            var Version = new Dictionary<string, string>();
            Version.Add("Windows", "v1.0");
            Parameters.CompilerOptions = "/target:winexe";
            cResults = Compiler.CompileAssemblyFromSource(Parameters, source);
            if (cResults.Errors.Count > 0)
            {
                foreach (CompilerError error in cResults.Errors)
                    MessageBox.Show("Error: " + error.ErrorText, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
开发者ID:Methh,项目名称:CooLogger,代码行数:28,代码来源:AdvancedForm.cs


示例10: 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


示例11: 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


示例12: SetUp

		public override void SetUp ()
		{
			base.SetUp ();
			_typeDeclaration = new CodeTypeDeclaration ();

			CodeDomProvider provider = new VBCodeProvider ();
			_codeGenerator = provider.CreateGenerator ();
		}
开发者ID:Profit0004,项目名称:mono,代码行数:8,代码来源:CodeGeneratorFromTypeTest.cs


示例13: 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


示例14: VisualBasicLanguage

        public VisualBasicLanguage()
        {
            _codeProvider = new VBCodeProvider();

            using (var fileStream = File.Open(Path.Combine(Application.StartupPath, "Languages", "Net", "VisualBasic.xml"), FileMode.Open, FileAccess.Read))
            {
                var serializer = new XmlSerializer(typeof(NetLanguageData));
                _data = (NetLanguageData)serializer.Deserialize(fileStream);
            }
            _keywords = _data.Keywords.MergeWith(_data.Modifiers).MergeWith(_data.MemberIdentifiers);
        }
开发者ID:die-Deutsche-Orthopaedie,项目名称:LiteDevelop,代码行数:11,代码来源:VisualBasicLanguage.cs


示例15: EscapeStringForLanguage

 public static string EscapeStringForLanguage(string input, QueryLanguage language)
 {
     CodeDomProvider provider;
     StringWriter writer = new StringWriter();
     if (language <= QueryLanguage.Program)
     {
         provider = new CSharpCodeProvider();
     }
     else
     {
         provider = new VBCodeProvider();
     }
     provider.GenerateCodeFromExpression(new CodePrimitiveExpression(input), writer, null);
     return writer.GetStringBuilder().ToString();
 }
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:15,代码来源:StringUtil.cs


示例16: Compile

        internal static TemplateCompilationResult Compile(
            Type templateType,
            string templateBody,
            IEnumerable<string> assemblyFileNames,
            IEnumerable<string> namespaces,
            string tempDirectory)
        {
            LoadRuntimeBinder();

            string className;
            var compileUnit = GetCodeCompileUnit(templateType, namespaces, templateBody, out className);

            string sourceCode;
            CodeDomProvider codeProvider;
            switch (Language)
            {
             case TemplateCompilationLanguage.CSharp:
                    codeProvider = new CSharpCodeProvider();
                    break;
                case TemplateCompilationLanguage.VisualBasic:
                    codeProvider = new VBCodeProvider();
                    break;
                default:
                    throw new NotSupportedException("Language not supported.");
            }
            var builder = new StringBuilder();

            using (var writer = new StringWriter(builder, CultureInfo.InvariantCulture))
            {
                codeProvider.GenerateCodeFromCompileUnit(compileUnit, writer, new CodeGeneratorOptions());
                sourceCode = builder.ToString();
            }

            var parameters = CreateCompilerParameters(tempDirectory, assemblyFileNames);
            var compileResult = codeProvider.CompileAssemblyFromDom(parameters, compileUnit);
            if (compileResult.Errors != null && compileResult.Errors.Count > 0)
                throw new TemplateCompilationException(compileResult.Errors, sourceCode, templateBody);

            var fullClassName = TEMPLATES_NAMESPACE + "." + className;

            return new TemplateCompilationResult
            {
                Type = compileResult.CompiledAssembly.GetType(fullClassName),
                SourceCode = sourceCode
            };
        }
开发者ID:volkovku,项目名称:RazorTemplates,代码行数:46,代码来源:TemplateCompiler.cs


示例17: Load

        public static void Load(PluginInterface.logprintf_t logprint, string indent)
        {
            LogPrint = logprint;
            Indent = indent;
            if (!Directory.Exists(WorkingDir))
                Directory.CreateDirectory(WorkingDir);

            ConvertIncludes();

            CompilerParameters parameters = new CompilerParameters();
            parameters.GenerateExecutable = false;
            parameters.GenerateInMemory = false;
            parameters.ReferencedAssemblies.AddRange(Assembly.GetExecutingAssembly().GetReferencedAssemblies().Select(entry => entry.Name).ToArray());
            parameters.WarningLevel = 4;

            string[] csfiles = Directory.GetFiles(WorkingDir, "*.cs");
            LogPrint(Indent + "Loading " + csfiles.Length + " CSharp files...");
            foreach (string file in csfiles)
            {
                PrepCompilerParameters(file, parameters);
                //if (csfiles.Length > 0)
                //{
                CSharpCodeProvider csprovider = new CSharpCodeProvider();
                //CompilerResults results = csprovider.CompileAssemblyFromFile(parameters, csfiles);
                CompilerResults results = csprovider.CompileAssemblyFromFile(parameters, file);
                Parse(results);
                //}
                //parameters.ReferencedAssemblies.Add(file); //Hozzáadja az aktuális fájlt a következőhöz, hogy... - Csak a legutolsó kapná meg az összeset
            }
            LogPrint(Indent + "Loaded " + csfiles.Length + " CSharp files.");

            string[] vbfiles = Directory.GetFiles(WorkingDir, "*.vb");
            LogPrint(Indent + "Loading " + vbfiles.Length + " VisualBasic files...");
            //if (vbfiles.Length > 0)
            foreach (string file in vbfiles)
            {
                PrepCompilerParameters(file, parameters);
                VBCodeProvider vbprovider = new VBCodeProvider();
                CompilerResults results = vbprovider.CompileAssemblyFromFile(parameters, vbfiles);
                Parse(results);
            }
            LogPrint(Indent + "Loaded " + vbfiles.Length + " VisualBasic files.");
        }
开发者ID:NorbiPeti,项目名称:CSharp2Pawn,代码行数:43,代码来源:CompileNRun.cs


示例18: CompileAndRun

        public dynamic CompileAndRun(string engine, string expression, ScriptScope scope)
        {
            _eventHandler.BeforeCompilation(new BeforeDotNetCompilationContext(scope));

            var parameters = new CompilerParameters { GenerateInMemory = true, TreatWarningsAsErrors = false };
            foreach (var item in scope.Assemblies) parameters.ReferencedAssemblies.Add(item.Location);

            CompilerResults result;
            var providerOptions = new Dictionary<string, string>() { { "CompilerVersion", "v4.0" } };
            switch (engine)
            {
                case "C#":
                    result = new CSharpCodeProvider(providerOptions).CompileAssemblyFromSource(parameters, expression);
                    break;
                case "VB":
                    result = new VBCodeProvider(providerOptions).CompileAssemblyFromSource(parameters, expression);
                    break;
                default:
                    throw new ArgumentException(T("Undefined .NET scripting engine.").ToString());
            }

            _eventHandler.AfterCompilation(new AfterDotNetCompilationContext(scope, result));

            if (result.Errors.HasErrors)
            {
                var builder = new StringBuilder();
                foreach (var item in result.Errors) builder.Append(Environment.NewLine + item);
                throw new ScriptRuntimeException(Environment.NewLine + T("The following compile error(s) need to be fixed:") + builder.ToString());
            }

            var entryClass = result.CompiledAssembly.CreateInstance("DotNetScripting");

            _eventHandler.BeforeExecution(new BeforeDotNetExecutionContext(scope));

            var scriptResult = entryClass.GetType().GetMethod("Main").Invoke(entryClass, new object[] { });

            _eventHandler.AfterExecution(new AfterDotNetExecutionContext(scope));

            return scriptResult;
        }
开发者ID:Lombiq,项目名称:Orchard-Scripting-Extensions-DotNet,代码行数:40,代码来源:DotNetRuntime.cs


示例19: CreateCodeProviderInstance

        internal static CodeDomProvider CreateCodeProviderInstance(Type type, string compilerVersion)
        {
            CodeDomProvider provider = null;
            if (string.IsNullOrEmpty(compilerVersion))
            {
                if (type == typeof(CSharpCodeProvider))
                    provider = new CSharpCodeProvider();
                else if (type == typeof(VBCodeProvider))
                    provider = new VBCodeProvider();
                else
                    provider = (CodeDomProvider)Activator.CreateInstance(type);
            }
            else
            {
                //otherwise pass the compiler version parameter into it
                Dictionary<string, string> options = new Dictionary<string, string>();
                options.Add(CompilerHelpers.CompilerVersionKeyword, compilerVersion);
                provider = (CodeDomProvider)Activator.CreateInstance(type, new object[] { options });
            }

            return provider;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:22,代码来源:CompilerHelpers.cs


示例20: Compile

        /// <summary>
        /// Compile source code
        /// </summary>
        /// <param name="code">full source code to compile</param>
        /// <param name="references">assembly references</param>
        /// <param name="language">target language</param>
        /// <param name="compilerVersion">compiler version</param>
        public void Compile(string code, string[] references, ESupportedLanguage language, String compilerVersion)
        {
            var properties = new Dictionary<string, string> {{CompilerVersion, compilerVersion}};
            CodeDomProvider provider;

            switch (language)
            {
                case ESupportedLanguage.CSharp:
                    provider = new CSharpCodeProvider(properties);
                    break;
                case ESupportedLanguage.VisualBasic:
                    provider = new VBCodeProvider(properties);
                    break;
                default:
                    throw new ArgumentException();
            }

            var parameters = new CompilerParameters
            {
                GenerateExecutable = false,
                GenerateInMemory = false,
                IncludeDebugInformation = false
            };

            parameters.ReferencedAssemblies.AddRange(references);

            if (language == ESupportedLanguage.CSharp)
            {
                parameters.CompilerOptions = "/unsafe";
            }

            var results = provider.CompileAssemblyFromSource(parameters, code);
            AssemblyLocation = null;
            Errors = results.Errors;

            if (!results.Errors.HasErrors)
                AssemblyLocation = results.CompiledAssembly.Location;
        }
开发者ID:SAD1992,项目名称:justdecompile-plugins,代码行数:45,代码来源:Compiler.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# FileIO.TextFieldParser类代码示例发布时间:2022-05-26
下一篇:
C# VisualBasic.Collection类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap