本文整理汇总了C#中System.CodeDom.Compiler.IndentedTextWriter类的典型用法代码示例。如果您正苦于以下问题:C# IndentedTextWriter类的具体用法?C# IndentedTextWriter怎么用?C# IndentedTextWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IndentedTextWriter类属于System.CodeDom.Compiler命名空间,在下文中一共展示了IndentedTextWriter类的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: Convert
public static string Convert(string fileName, out SwfCompilationUnit scu, out VexObject v)
{
v = null;
string result = "Failed to convert.";
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
string name = Path.GetFileNameWithoutExtension(fileName);
SwfReader r = new SwfReader(br.ReadBytes((int)fs.Length));
scu = new SwfCompilationUnit(r, name);
if (scu.IsValid)
{
result = "\n\n**** Converting to SwfCompilationUnit ****\n";
#if DEBUG
StringWriter sw = new StringWriter();
IndentedTextWriter w = new IndentedTextWriter(sw);
scu.Dump(w);
Debug.WriteLine(sw.ToString());
#endif
result += scu.Log.ToString();
SwfToVex s2v = new SwfToVex();
v = s2v.Convert(scu);
result += "\n\n**** Converting to Vex ****\n";
result += s2v.Log.ToString();
}
return result;
}
示例3: Dump
public void Dump(IndentedTextWriter w)
{
w.Write("Line [");
w.Write("dx: " + this.DeltaX + ", ");
w.Write("dy: " + this.DeltaY);
w.Write("]");
}
示例4: WriteHelper
//===========================================================================================
private void WriteHelper(IndentedTextWriter writer)
{
writer.WriteLine("public static class ExceptionHelper");
WriteStartColon(writer);
writer.WriteLine("public static Exception Create(Exception exception)");
WriteStartColon(writer);
writer.WriteLine("if (ReferenceEquals(exception, null))");
writer.Indent++;
writer.WriteLine("return null;");
writer.Indent--;
writer.WriteLine("switch(exception.GetType().Name)");
WriteStartColon(writer);
foreach (Type exception in _Exceptions)
{
writer.Write("case \"");
writer.Write(exception.Name);
writer.WriteLine("\":");
writer.Indent++;
writer.Write("return new ");
writer.Write(exception.Name);
writer.WriteLine("(exception);");
writer.Indent--;
}
writer.WriteLine("default:");
writer.Indent++;
writer.WriteLine("return exception;");
writer.Indent--;
WriteEndColon(writer);
WriteEndColon(writer);
WriteEndColon(writer);
}
示例5: WriteSet
//===========================================================================================
protected override void WriteSet(IndentedTextWriter writer, PropertyInfo property)
{
writer.Write("image->");
writer.Write(property.Name);
writer.Write(" = ");
WriteGetValue(writer, property);
}
示例6: WriteFileTrailer
private void WriteFileTrailer(IndentedTextWriter writer)
{
writer.Indent -= 2;
while (!template.EndOfStream)
writer.WriteLine(template.ReadLine());
}
示例7: AppendDDL
public override void AppendDDL(IndentedTextWriter textWriter)
{
if (Note.Length > 0)
{
textWriter.WriteLine("/*");
textWriter.Write(" ");
textWriter.WriteLine(Note);
textWriter.WriteLine("*/");
}
textWriter.WriteLine($"IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{ObjectIdentifier}'))");
textWriter.WriteLine($"CREATE TABLE {ObjectIdentifier} (");
textWriter.Indent++;
foreach (var column in Columns)
{
column.AppendDDL(textWriter, includeConstraints: true);
textWriter.WriteLine(",");
}
foreach (var constraint in Constraints)
{
constraint.AppendDDL(textWriter);
textWriter.WriteLine(",");
}
textWriter.Indent--;
textWriter.WriteLine(");");
textWriter.WriteLine("GO");
}
示例8: WriteText
public override void WriteText(IndentedTextWriter writer)
{
writer.WriteLine("CResourceIntrospectionManifest");
writer.WriteLine("{");
writer.Indent++;
writer.WriteLine("uint32 m_nIntrospectionVersion = 0x{0:x8}", IntrospectionVersion);
writer.WriteLine("Struct m_ReferencedStructs[{0}] =", ReferencedStructs.Count);
writer.WriteLine("[");
writer.Indent++;
foreach (var refStruct in ReferencedStructs)
{
refStruct.WriteText(writer);
}
writer.Indent--;
writer.WriteLine("]");
writer.WriteLine("Struct m_ReferencedEnums[{0}] =", ReferencedEnums.Count);
writer.WriteLine("[");
writer.Indent++;
foreach (var refEnum in ReferencedEnums)
{
refEnum.WriteText(writer);
}
writer.Indent--;
writer.WriteLine("]");
writer.Indent--;
writer.WriteLine("}");
}
示例9: AppendDDL
public override void AppendDDL(IndentedTextWriter textWriter)
{
if (!string.IsNullOrEmpty(Note))
{
textWriter.WriteLine("/*");
textWriter.Write(" ");
textWriter.WriteLine(Note);
textWriter.WriteLine("*/");
}
textWriter.WriteLine($"IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'{ObjectIdentitifer}') AND name = N'{Name}')");
textWriter.WriteLine($"CREATE {(IsUnique ? "UNIQUE " : "")}{(IsClusterd ? "CLUSTERED" : "NONCLUSTERED")} INDEX [{Name}] ON {ObjectIdentitifer} (");
textWriter.Write(" ");
textWriter.WriteLine(string.Join("," + Environment.NewLine + " ", KeyColumns));
textWriter.Write(")");
if (IncludedColumns != null && IncludedColumns.Any())
{
textWriter.WriteLine();
textWriter.WriteLine("INCLUDE (");
textWriter.Write(" ");
textWriter.WriteLine(string.Join("," + Environment.NewLine + " ", IncludedColumns));
textWriter.Write(")");
}
if (!string.IsNullOrEmpty(FilterDefinition))
{
textWriter.WriteLine();
textWriter.WriteLine("WHERE ");
textWriter.Write(FilterDefinition);
}
textWriter.WriteLine(";");
textWriter.WriteLine("GO");
}
示例10: CreateOutput
public override string CreateOutput()
{
RemoveComments = Generators.Any(p => !p.AlwaysRegenerate);
Namespace = new CodeNamespace(NamespaceName);
Unit = new CodeCompileUnit();
Unit.Namespaces.Add(Namespace);
foreach (var codeGenerator in Generators.Where(p=>p.IsValid()))
{
// UnityEngine.Debug.Log(codeGenerator.GetType().Name + " is generating");
codeGenerator.Initialize(this);
}
var provider = new CSharpCodeProvider();
var sb = new StringBuilder();
var tw1 = new IndentedTextWriter(new StringWriter(sb), " ");
provider.GenerateCodeFromCompileUnit(Unit, tw1, new CodeGeneratorOptions());
tw1.Close();
if (RemoveComments)
{
var removedLines = sb.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Skip(10).ToArray();
return string.Join(Environment.NewLine, removedLines);
}
return sb.ToString();
}
示例11: Write
/// <summary>
/// Converts a given coordinate system object to a WKT string.
/// </summary>
/// <param name="obj">The coordinate system object to convert.</param>
/// <returns>A string containing WKT.</returns>
public static string Write(object obj)
{
TextWriter textwriter = new StringWriter();
IndentedTextWriter indentedWriter = new IndentedTextWriter(textwriter);
Write(obj, indentedWriter);
return textwriter.ToString();
}
示例12: WriteCode
//===========================================================================================
public virtual void WriteCode(IndentedTextWriter writer)
{
writer.Write(TypeName);
writer.Write(" MagickScript::Create");
writer.Write(ClassName);
writer.WriteLine("(XmlElement^ element)");
WriteStartColon(writer);
WriteMethod(writer, Constructors);
WriteEndColon(writer);
if (!WriteEnumerable)
return;
writer.Write("Collection<");
writer.Write(TypeName);
writer.Write(">^ MagickScript::Create");
writer.Write(ClassName);
writer.WriteLine("s(XmlElement^ element)");
WriteStartColon(writer);
writer.Write("Collection<");
writer.Write(TypeName);
writer.Write(">^ collection = gcnew Collection<");
writer.Write(TypeName);
writer.WriteLine(">();");
writer.WriteLine("for each (XmlElement^ elem in element->SelectNodes(\"*\"))");
WriteStartColon(writer);
writer.Write("collection->Add(Create");
writer.Write(TypeName.Replace("^", ""));
writer.WriteLine("(elem));");
WriteEndColon(writer);
writer.WriteLine("return collection;");
WriteEndColon(writer);
}
示例13: WriteMessages
private static void WriteMessages(this StringWriter writer, Exception e)
{
using (var indentedWriter = new IndentedTextWriter(writer, " "))
{
WriteMessages(indentedWriter, e);
}
}
示例14: AppendDDL
public override void AppendDDL(IndentedTextWriter textWriter)
{
if (!string.IsNullOrEmpty(Note))
{
textWriter.WriteLine("/*");
textWriter.Write(" ");
textWriter.WriteLine(Note);
textWriter.WriteLine("*/");
}
textWriter.WriteLine($"IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{ForeignKey.QuotedForeignKeyName}'))");
textWriter.Indent++;
textWriter.WriteLine($"ALTER TABLE {ForeignKey.ParentObjectIdentifier}");
textWriter.Indent++;
textWriter.Write("ADD ");
textWriter.Indent++;
ForeignKey.AppendDDL(textWriter);
textWriter.WriteLine(";");
textWriter.Indent--;
textWriter.Indent--;
textWriter.Indent--;
textWriter.WriteLine("GO");
}
示例15: PrintException
private static void PrintException(IndentedTextWriter iWriter, Exception ex) {
if (ex == null) {
iWriter.WriteLine("(null)");
return;
}
iWriter.WriteLine("[{0}]", ex.GetType());
iWriter.Indent++;
iWriter.WriteLine("Message: {0}", ex.Message);
iWriter.WriteLine("Source: {0}", ex.Source);
iWriter.WriteLine("TargetSite: {0}", ex.TargetSite);
iWriter.WriteLine("HelpLink: {0}", ex.HelpLink);
if (ex.Data.Count > 0) {
iWriter.WriteLine("Data:");
iWriter.Indent++;
foreach (var key in ex.Data.Keys) {
iWriter.WriteLine("• {0} = {1}", key, ex.Data[key]);
}
iWriter.Indent--;
}
iWriter.WriteLine("Full Stack Trace:");
iWriter.Indent++;
PrintStackTrace(iWriter, new StackTrace(ex, true));
iWriter.Indent--;
iWriter.WriteLine("Inner Exception: ");
iWriter.Indent++;
PrintException(iWriter, ex.InnerException);
iWriter.Indent--;
}