本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例5: TestUtilities
static TestUtilities()
{
cSharpCompiler = new CSharpCodeProvider();
compiler = cSharpCompiler.CreateCompiler();
compileParameters = new CompilerParameters();
vbCompilerProvider = new VBCodeProvider();
vbCompiler = vbCompilerProvider.CreateCompiler();
vbCompileParameters = new CompilerParameters();
}
示例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;
}
示例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);
}
}
示例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;
}
示例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...");
}
}
示例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;
}
示例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;
}
示例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;
}