本文整理汇总了C#中System.CodeDom.Compiler.CodeGeneratorOptions类的典型用法代码示例。如果您正苦于以下问题:C# CodeGeneratorOptions类的具体用法?C# CodeGeneratorOptions怎么用?C# CodeGeneratorOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodeGeneratorOptions类属于System.CodeDom.Compiler命名空间,在下文中一共展示了CodeGeneratorOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainForm
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
CodeCompileUnit cu = GeneraCodigo();
CodeDomProvider dp = CodeDomProvider.CreateProvider("CSharp");
//Imprimir el código
StringWriter sw = new StringWriter();
System.CodeDom.Compiler.IndentedTextWriter itw = new IndentedTextWriter(sw);
CodeGeneratorOptions go = new CodeGeneratorOptions();
go.BlankLinesBetweenMembers = false;
dp.GenerateCodeFromCompileUnit(cu,sw,go);
this.tbFuenteGenerado.Text = sw.ToString();
//Compilar desde dom
CompilerParameters cp = new CompilerParameters(new string[]{},"borrame.dll");
CompilerResults cr = dp.CompileAssemblyFromDom(cp,cu);
tbErrores.Text = "";
foreach(CompilerError ce in cr.Errors){
tbErrores.Text += String.Format("{0}){1} in {2} at line {3} column {4} isWarning{5}",ce.ErrorNumber,ce.ErrorText,ce.FileName,ce.Line,ce.Column,ce.IsWarning);
}
}
示例2: TypescriptSnippetTypeMember
public TypescriptSnippetTypeMember(
CodeSnippetTypeMember member,
CodeGeneratorOptions options)
{
_member = member;
_options = options;
}
示例3: Build
public void Build(DataStructure dataStructure, string rendererFilename = "")
{
if (string.IsNullOrEmpty(rendererFilename)) { rendererFilename = this.GetFilename(dataStructure); }
var rendererType = new CodeTypeDeclaration(dataStructure.RendererName);
rendererType.IsClass = true;
rendererType.IsPartial = true;
rendererType.BaseTypes.Add(typeof(Renderer));
rendererType.Comments.Add(new CodeCommentStatement("<summary>", true));
rendererType.Comments.Add(new CodeCommentStatement(string.Format("Renderer of {0}", dataStructure.TargetName), true));
rendererType.Comments.Add(new CodeCommentStatement("</summary>", true));
BuildCreate(rendererType, dataStructure);
BuildConstructor(rendererType, dataStructure);
BuildDoInitialize(rendererType, dataStructure);
BuildDoRender(rendererType, dataStructure);
var parserNamespace = new CodeNamespace("CSharpGL");
parserNamespace.Imports.Add(new CodeNamespaceImport(typeof(System.Object).Namespace));
parserNamespace.Imports.Add(new CodeNamespaceImport(typeof(System.Collections.Generic.List<int>).Namespace));
parserNamespace.Types.Add(rendererType);
//生成代码
using (var stream = new StreamWriter(rendererFilename, false))
{
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
CodeGeneratorOptions opentions = new CodeGeneratorOptions();//代码生成选项
opentions.BlankLinesBetweenMembers = true;
opentions.BracingStyle = "C";
opentions.ElseOnClosing = false;
opentions.IndentString = " ";
opentions.VerbatimOrder = true;
codeProvider.GenerateCodeFromNamespace(parserNamespace, stream, opentions);
}
}
示例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: WriteCodeFiles
/// <summary>
/// Writes the code to the disk according to the given options.
/// </summary>
private void WriteCodeFiles()
{
// Ensure the output directory exist in the file system.
EnsureDirectoryExists(options.OutputLocation);
// Create the CodeGenerationOptions instance.
codeGenerationOptions = CodeWriter.CreateCodeGeneratorOptions();
// Do we have to generate separate files?
if (options.GenerateSeparateFiles)
{
// Write the code into separate files.
WriteSeparateCodeFiles();
}
else
{
// Write the code into a singl file.
WriteSingleCodeFile();
}
// Finally write the configuration file.
if (configuration != null)
{
WriteConfigurationFile();
}
WriteTextFiles();
}
示例6: GenerateHelper
private void GenerateHelper()
{
using (GenParamsForm gpf = new GenParamsForm())
{
gpf.Namespace = _rootCategory.Name;
if (gpf.ShowDialog(this) == DialogResult.OK)
{
CodeCompileUnit ccu = HelperGenerator.Generate(_rootCategory,
gpf.Namespace, gpf.IsInternal);
CSharpCodeProvider cscp = new CSharpCodeProvider();
CodeGeneratorOptions cgo = new CodeGeneratorOptions();
cgo.BracingStyle = "C";
using (StreamWriter sw = new StreamWriter(
Path.Combine(_directory, _rootCategory.TreeName + ".cs")))
cscp.GenerateCodeFromCompileUnit(ccu, sw, cgo);
if (gpf.ShowResult)
using (ShowResultForm srf = new ShowResultForm())
using (StringWriter strW = new StringWriter())
{
cscp.GenerateCodeFromCompileUnit(ccu, strW, cgo);
srf.Result = strW.ToString();
srf.ShowDialog(this);
}
}
}
}
示例7: Main
static void Main(string[] args)
{
// 输出所有支持生成代码的语言
foreach (CompilerInfo ci in CodeDomProvider.GetAllCompilerInfo())
{
foreach (var language in ci.GetLanguages())
{
Console.Write("{0} ", language);
}
Console.WriteLine();
}
CodeNamespace prgNamespace = BuildProgram();
var compilerOptions = new CodeGeneratorOptions()
{
IndentString = " ",
BracingStyle = "C", // 花括号的风格
BlankLinesBetweenMembers = false
};
var codeText = new StringBuilder();
using (var codeWriter = new StringWriter(codeText))
{
CodeDomProvider.CreateProvider("c#").GenerateCodeFromNamespace(
prgNamespace, codeWriter, compilerOptions);
}
var script = codeText.ToString();
Console.WriteLine(script);
Console.Read();
}
示例8: CodeSnippetBlankLines
public void CodeSnippetBlankLines ()
{
var opt = new CodeGeneratorOptions () {
BlankLinesBetweenMembers = false,
VerbatimOrder = false
};
var ccu = new CodeCompileUnit ();
var ns = new CodeNamespace ("Foo");
ccu.Namespaces.Add (ns);
var t = new CodeTypeDeclaration ("Bar");
ns.Types.Add (t);
t.Members.Add (new CodeSnippetTypeMember ("#line hidden"));
t.Members.Add (new CodeSnippetTypeMember ("#line hidden2"));
t.Members.Add (new CodeMemberMethod () { Name = "Foo" });
using (var sw = new StringWriter ()) {
new CSharpCodeProvider ().GenerateCodeFromCompileUnit (ccu, sw, opt);
var str = sw.ToString ();
Assert.IsFalse (str.Contains ("hidden2private"), "#0");
Assert.IsTrue (str.Contains( "#line hidden#line hidden2"), "#1");
}
}
示例9: GenerateCS
private void GenerateCS()
{
using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
{
CodeGeneratorOptions opts = new CodeGeneratorOptions();
StringWriter sw = new StringWriter();
provider.GenerateCodeFromMember(_method, sw, opts);
StringReader sr = new StringReader(sw.GetStringBuilder().ToString());
string line = sr.ReadLine();
while (string.IsNullOrEmpty(line))
line = sr.ReadLine();
int idx = line.IndexOf(" " + _method.Name + "(");
idx = line.LastIndexOf(' ', idx - 1);
if (_method.Statements.Count > 0)
{
Text = "partial" + line.Remove(0, idx);
Text = sw.GetStringBuilder().Replace(line, Text).ToString();
}
else
{
line = "partial" + line.Remove(0, idx);
idx = line.LastIndexOf(')');
Text = line.Remove(idx + 1) + ";" + Environment.NewLine;
}
}
}
示例10: Generate
/// <summary>
/// Generate the actual code to the given writer.
/// </summary>
public void Generate(TextWriter writer)
{
var provider = CodeDomProvider.CreateProvider("CSharp");
var options = new CodeGeneratorOptions { BracingStyle = "C" };
provider.GenerateCodeFromCompileUnit(codeCompileUnit, writer, options);
writer.Flush();
}
示例11: Build
public void Build(DataStructure dataStructure, string modelFilename = "")
{
if (string.IsNullOrEmpty(modelFilename)) { modelFilename = this.GetFilename(dataStructure); }
// public class DemoModel : IBufferable { }
var modelType = new CodeTypeDeclaration(dataStructure.ModelName);
modelType.IsClass = true;
modelType.IsPartial = true;
modelType.BaseTypes.Add(typeof(IBufferable));
modelType.Comments.Add(new CodeCommentStatement("<summary>", true));
modelType.Comments.Add(new CodeCommentStatement(string.Format("Model of {0}", dataStructure.TargetName), true));
modelType.Comments.Add(new CodeCommentStatement("</summary>", true));
BuildFields(modelType, dataStructure);
BuildGetVertexAttributeBuffer(modelType, dataStructure);
BuildGetIndex(modelType, dataStructure);
var parserNamespace = new CodeNamespace("CSharpGL");
parserNamespace.Imports.Add(new CodeNamespaceImport(typeof(System.Object).Namespace));
parserNamespace.Imports.Add(new CodeNamespaceImport(typeof(System.Collections.Generic.List<int>).Namespace));
parserNamespace.Types.Add(modelType);
//生成代码
using (var stream = new StreamWriter(modelFilename, false))
{
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
CodeGeneratorOptions opentions = new CodeGeneratorOptions();//代码生成选项
opentions.BlankLinesBetweenMembers = true;
opentions.BracingStyle = "C";
opentions.ElseOnClosing = false;
opentions.IndentString = " ";
opentions.VerbatimOrder = true;
codeProvider.GenerateCodeFromNamespace(parserNamespace, stream, opentions);
}
}
示例12: Nullify
public void Nullify ()
{
CodeGeneratorOptions cgo = new CodeGeneratorOptions ();
cgo.BlankLinesBetweenMembers = false;
Assert.IsFalse (cgo.BlankLinesBetweenMembers, "BlankLinesBetweenMembers-1");
cgo["BlankLinesBetweenMembers"] = null;
Assert.IsTrue (cgo.BlankLinesBetweenMembers, "BlankLinesBetweenMembers-2");
cgo.BracingStyle = "C";
Assert.AreEqual ("C", cgo.BracingStyle, "BracingStyle-1");
cgo["BracingStyle"] = null;
Assert.AreEqual ("Block", cgo.BracingStyle, "BracingStyle-2");
cgo.ElseOnClosing = true;
Assert.IsTrue (cgo.ElseOnClosing, "ElseOnClosing-1");
cgo["ElseOnClosing"] = null;
Assert.IsFalse (cgo.ElseOnClosing, "ElseOnClosing-2");
cgo.IndentString = "\t";
Assert.AreEqual ("\t", cgo.IndentString, "IndentString-1");
cgo["IndentString"] = null;
Assert.AreEqual (" ", cgo.IndentString, "IndentString-2");
cgo.VerbatimOrder = true;
Assert.IsTrue (cgo.VerbatimOrder, "VerbatimOrder-1");
cgo["VerbatimOrder"] = null;
Assert.IsFalse (cgo.VerbatimOrder, "VerbatimOrder-2");
}
示例13: GenerateCodeFromStatement
public override void GenerateCodeFromStatement(CodeStatement statement,
TextWriter writer,
CodeGeneratorOptions options)
{
var codeExpressionStatement = statement as CodeExpressionStatement;
if (codeExpressionStatement != null)
{
var methodInvokeExpression =
codeExpressionStatement.Expression as CodeMethodInvokeExpression;
if (methodInvokeExpression != null)
{
if (methodInvokeExpression.Method.MethodName == "Write"
&& methodInvokeExpression.Parameters.Count == 1)
{
var parameter = methodInvokeExpression.Parameters[0] as CodeSnippetExpression;
if ((parameter != null) && (!string.IsNullOrEmpty(parameter.Value)))
{
// Appears to be a candidate for rewriting
string originalValue = parameter.Value;
var processor =
SnippetModifiers.OfType<ICodeSnippetTextModifier>()
.FirstOrDefault(m => m.CanProcessString(originalValue));
if (processor != null)
originalValue = processor.ProcessString(originalValue);
parameter.Value =
"global::" + GetType().FullName + ".PreProcessObject(this, "
+ originalValue + ")";
}
}
}
}
base.GenerateCodeFromStatement(statement, writer, options);
}
示例14: CreateSpecs
public string CreateSpecs(out int specCount)
{
var files = FindSpecFiles().ToArray();
specCount = files.Length;
if (specCount < 1)
return string.Empty;
var compile = new CodeCompileUnit();
var globalns = new CodeNamespace();
globalns.Imports.Add(new CodeNamespaceImport("NUnit.Framework"));
globalns.Imports.Add(new CodeNamespaceImport(config.MyNamespace));
compile.Namespaces.Add(globalns);
var specNamespace = new CodeNamespace(config.TargetNamespace + ".ChutzpahSpecs");
compile.Namespaces.Add(specNamespace);
foreach (var fileInfo in files)
{
AddSpec(specNamespace, fileInfo);
}
//specNamespace.Types.AddRange(files.Select(CreateSpec).ToArray());
var provider = CreateProvider();
var options = new CodeGeneratorOptions { BracingStyle = "C", BlankLinesBetweenMembers = false };
var stringBuilder = new StringBuilder();
using (var writer = new StringWriter(stringBuilder))
{
provider.GenerateCodeFromCompileUnit(compile, writer, options);
writer.Flush();
writer.Close();
}
var result = stringBuilder.ToString();
return result;
}
示例15: ParseToCode
public GeneratorResults ParseToCode(string TemplateCode, string defaultnamespace, string defaultclassname, string baseClassFullName)
{
GeneratorResults razorResults;
var host = new RazorEngineHost(new CSharpRazorCodeLanguage());
host.DefaultBaseClass = baseClassFullName;//typeof(BulaqTemplateForRazorBase).FullName;
host.DefaultNamespace = defaultnamespace;
host.DefaultClassName = defaultclassname;
host.NamespaceImports.Add("System");
host.NamespaceImports.Add("BulaqCMS.Models");
host.GeneratedClassContext = new GeneratedClassContext("Execute", "Write", "WriteLiteral");
var engine = new RazorTemplateEngine(host);
using (var reader = new StringReader(TemplateCode))
{
razorResults = engine.GenerateCode(reader);
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
CodeGeneratorOptions options = new CodeGeneratorOptions();
options.BracingStyle = "C";
using (StringWriter writer = new StringWriter())
{
IndentedTextWriter indentwriter = new IndentedTextWriter(writer, " ");
codeProvider.GenerateCodeFromCompileUnit(razorResults.GeneratedCode, indentwriter, options);
indentwriter.Flush();
indentwriter.Close();
LastGeneratedCode = writer.GetStringBuilder().ToString();
string codePath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\code.cs";
File.WriteAllText(codePath, LastGeneratedCode, Encoding.UTF8);
}
}
return razorResults;
}