本文整理汇总了C#中Microsoft.VisualBasic.VBCodeProvider.CreateGenerator方法的典型用法代码示例。如果您正苦于以下问题:C# VBCodeProvider.CreateGenerator方法的具体用法?C# VBCodeProvider.CreateGenerator怎么用?C# VBCodeProvider.CreateGenerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualBasic.VBCodeProvider
的用法示例。
在下文中一共展示了VBCodeProvider.CreateGenerator方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateGenerator_ReturnsSame
public void CreateGenerator_ReturnsSame()
{
VBCodeProvider provider = new VBCodeProvider();
#pragma warning disable 0618
Assert.Same(provider.CreateGenerator(), provider.CreateGenerator());
#pragma warning restore 0618
}
示例2: 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
}
示例3: 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
}
示例4: 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
}
示例5: SetUp
public override void SetUp ()
{
base.SetUp ();
_typeDeclaration = new CodeTypeDeclaration ();
CodeDomProvider provider = new VBCodeProvider ();
_codeGenerator = provider.CreateGenerator ();
}
示例6: UpdateCodeWindows
private void UpdateCodeWindows()
{
TabControl tc = this.host.GetService(typeof(TabControl)) as TabControl;
CodeGeneratorOptions o = new CodeGeneratorOptions();
o.BlankLinesBetweenMembers = true;
o.BracingStyle = "C";
o.ElseOnClosing = false;
o.IndentString = " ";
StringWriter sw = new StringWriter();
CSharpCodeProvider cs = new CSharpCodeProvider();
cs.CreateGenerator().GenerateCodeFromCompileUnit(this.codeCompileUnit, sw, o);
sw.Close();
sw = new StringWriter();
VBCodeProvider vb = new VBCodeProvider();
vb.CreateGenerator().GenerateCodeFromCompileUnit(this.codeCompileUnit, sw, o);
sw.Close();
sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
xtw.Formatting = Formatting.Indented;
this.xmlDocument.WriteTo(xtw);
string cleanup = sw.ToString().Replace("<DOCUMENT_ELEMENT>", "").Replace("</DOCUMENT_ELEMENT>", "");
sw.Close();
}
示例7: SetUp
public void SetUp ()
{
provider = new VBCodeProvider ();
generator = provider.CreateGenerator ();
options = new CodeGeneratorOptions ();
}
示例8: 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...");
}
}
示例9: Save
/// Save the current state of the loader. If the user loaded the file
/// or saved once before, then he doesn't need to select a file again.
/// Unless this is being called as a result of "Save As..." being clicked,
/// in which case forceFilePrompt will be true.
internal void Save(bool forceFilePrompt)
{
try
{
if (dirty)
{
// Flush any changes to the buffer.
Flush();
}
// If the buffer has no name or this is a "Save As...",
// prompt the user for a file name. The user can save
// either the C#, VB, or XML (though only the XML can be loaded).
//
int filterIndex = 3;
if ((fileName == null) || forceFilePrompt)
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.DefaultExt = "xml";
dlg.Filter = "Python Files|*.py|C# Files|*.cs|Visual Basic Files|*.vb|XML Files|*.xml";
if (dlg.ShowDialog() == DialogResult.OK)
{
fileName = dlg.FileName;
filterIndex = dlg.FilterIndex;
}
}
if (fileName != null)
{
switch (filterIndex)
{
case 1:
{
// Generate C# code from our codeCompileUnit and save it.
CodeGeneratorOptions o = new CodeGeneratorOptions();
o.BlankLinesBetweenMembers = true;
o.BracingStyle = "C";
o.ElseOnClosing = false;
o.IndentString = " ";
StreamWriter sw = new StreamWriter(fileName);
CSharpCodeProvider cs = new CSharpCodeProvider();
cs.CreateGenerator().GenerateCodeFromCompileUnit(codeCompileUnit, sw, o);
sw.Close();
} break;
case 2:
{
// Generate VB code from our codeCompileUnit and save it.
CodeGeneratorOptions o = new CodeGeneratorOptions();
o.BlankLinesBetweenMembers = true;
o.BracingStyle = "C";
o.ElseOnClosing = false;
o.IndentString = " ";
StreamWriter sw = new StreamWriter(fileName);
VBCodeProvider vb = new VBCodeProvider();
vb.CreateGenerator().GenerateCodeFromCompileUnit(codeCompileUnit, sw, o);
sw.Close();
} break;
case 3:
{
// Write out our xmlDocument to a file.
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
xtw.Formatting = Formatting.Indented;
xmlDocument.WriteTo(xtw);
// Get rid of our artificial super-root before we save out
// the XML.
//
string cleanup = sw.ToString().Replace("<DOCUMENT_ELEMENT>", "");
cleanup = cleanup.Replace("</DOCUMENT_ELEMENT>", "");
xtw.Close();
StreamWriter file = new StreamWriter(fileName);
file.Write(cleanup);
file.Close();
} break;
}
unsaved = false;
}
}
catch(Exception ex)
{
MessageBox.Show("Error during save: " + ex.Message);
}
}