public static void Write(IfStatement ifStatement, IndentedStreamWriter writer) { if (ifStatement.Ifs.Any()) { If @if = ifStatement.Ifs.First(); IEnumerable <If> elseIfs = ifStatement.Ifs.Skip(1); writer.WriteLine($"if ({@if.Condition})"); writer.OpenBrackets(); @if.Body(new BodyWriter(writer)); writer.CloseBrackets(); foreach (If elseIf in elseIfs) { writer.WriteLine($"if ({elseIf.Condition})"); writer.OpenBrackets(); elseIf.Body(new BodyWriter(writer)); writer.CloseBrackets(); } } else { writer.WriteLine("if (false)"); writer.OpenBrackets(); writer.CloseBrackets(); } if (ifStatement.ElseBody is { })
public static async Task WriteAsync(Class c, Stream stream) { var writer = new IndentedStreamWriter(stream); var usingWriter = new UsingWriter(writer); var namespaceWriter = new NamespaceWriter(writer, c.Namespace); BaseWriter[] bodyWriters = new BaseWriter[] { new FieldWriter(writer, c.Fields), new ConstructorWriter(writer, c.ClassName, c.Ctors), new PropertyWriter(writer, c.Properties), new MethodWriter(writer, c.Methods) }; foreach (string?u in c.Usings) { usingWriter.AddUsing(u); } if (usingWriter.Make()) { await writer.WriteLineAsync(); } var classDescription = new List <string>(); if (c.Accessibility.HasValue) { classDescription.Add(c.Accessibility.Value.ToSharpieString()); } if (c.Static) { classDescription.Add("static"); } if (c.Partial) { classDescription.Add("partial"); } classDescription.Add("class"); classDescription.Add(c.ClassName); namespaceWriter.Begin(); await writer.WriteLineAsync(string.Join(" ", classDescription) + c.GetInheritance()); await writer.WriteLineAsync("{"); writer.IndentationLevel++; BaseWriter?prevWriter = null; bool prevWroteSomething = false; foreach (BaseWriter bodyWriter in bodyWriters) { if (prevWriter is { } && prevWroteSomething)
public static async Task WriteAsync(If @if, IndentedStreamWriter writer) { await writer.WriteLineAsync($"if ({@if.Condition})"); await writer.WriteLineAsync("{").ConfigureAwait(false); writer.IndentationLevel++; var bodyWriter = new BodyWriter(writer); @if.Body(bodyWriter); writer.IndentationLevel--; await writer.WriteLineAsync("}").ConfigureAwait(false); }
public static async Task WriteAsync(SwitchCaseStatement switchCaseStatement, IndentedStreamWriter writer) { await writer.WriteLineAsync($"switch ({switchCaseStatement.Expression})"); await writer.WriteLineAsync("{"); writer.IndentationLevel++; var bodyWriter = new BodyWriter(writer); foreach (CaseStatement @case in switchCaseStatement.CaseStatements) { await writer.WriteLineAsync($"case {@case.Case}:"); writer.IndentationLevel++; @case.Body(bodyWriter); writer.IndentationLevel--; } if (switchCaseStatement.DefaultCaseBody is { })
public UsingWriter(IndentedStreamWriter writer, IEnumerable <string> usings) : base(writer) => _usings = new HashSet <string>(usings);
public BodyWriter(IndentedStreamWriter writer) => _writer = writer;
public PropertyWriter(IndentedStreamWriter writer, IEnumerable <Property> properties) : this(writer) => _properties.AddRange(properties);
public PropertyWriter(IndentedStreamWriter writer) : base(writer) { }
protected BaseWriter(IndentedStreamWriter writer) => _writer = writer;
public FieldWriter(IndentedStreamWriter writer, IEnumerable <Field> fields) : this(writer) => _fields.AddRange(fields);
public FieldWriter(IndentedStreamWriter writer) : base(writer) { }
public ConstructorWriter(IndentedStreamWriter writer, string name) : base(writer) => _name = name;
Dispose(true); // TODO: uncomment the following line if the finalizer is overridden above.// GC.SuppressFinalize(this); #endregion public static void NopWriter(IndentedStreamWriter writer) { }