本文整理汇总了C#中Microsoft.VisualBasic.VBCodeProvider类的典型用法代码示例。如果您正苦于以下问题:C# VBCodeProvider类的具体用法?C# VBCodeProvider怎么用?C# VBCodeProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VBCodeProvider类属于Microsoft.VisualBasic命名空间,在下文中一共展示了VBCodeProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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
}
示例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
}
示例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);
}
}
示例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);
}
}
示例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
}
示例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
}
示例12: SetUp
public override void SetUp ()
{
base.SetUp ();
_typeDeclaration = new CodeTypeDeclaration ();
CodeDomProvider provider = new VBCodeProvider ();
_codeGenerator = provider.CreateGenerator ();
}
示例13: TestUtilities
static TestUtilities()
{
cSharpCompiler = new CSharpCodeProvider();
compiler = cSharpCompiler.CreateCompiler();
compileParameters = new CompilerParameters();
vbCompilerProvider = new VBCodeProvider();
vbCompiler = vbCompilerProvider.CreateCompiler();
vbCompileParameters = new CompilerParameters();
}
示例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);
}
示例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();
}