/// <summary> /// Executes provided action and returns all code, generated by it. /// </summary> /// <param name="fragmentBuilder">Code generation action.</param> /// <returns>Code, generated by <paramref name="fragmentBuilder"/>.</returns> protected string BuildFragment(Action fragmentBuilder) { var mainWriter = _writer; try { var writer = _writer = new IndentedWriter(_newLine, _indent); fragmentBuilder(); return(writer.GetText()); } finally { _writer = mainWriter; } }
/// <summary> /// Constructor. /// </summary> /// <param name="newLine">Sequence of characters, used as new line by code writer.</param> /// <param name="indent">Sequence of characters, used as one level of indent.</param> protected CodeGenerationVisitor(string newLine, string indent) { _newLine = newLine; _indent = indent; _writer = new IndentedWriter(newLine, indent); }