/// <summary>
 /// Write text directly into the generated output
 /// </summary>
 public T WriteLine(string textToAppend)
 {
     Write(textToAppend);
     GenerationText.AppendLine();
     _endsWithNewline = true;
     return((T)this);
 }
 /// <summary>
 /// Write text directly into the generated output
 /// </summary>
 public T Write(string textToAppend)
 {
     if (string.IsNullOrEmpty(textToAppend))
     {
         return((T)this);
     }
     // If we're starting off, or if the previous text ended with a newline,
     // we have to append the current indent first.
     if (GenerationText.Length == 0 || _endsWithNewline)
     {
         GenerationText.Append(_currentIndent);
         _endsWithNewline = false;
     }
     // Check if the current text ends with a newline
     if (textToAppend.EndsWith(Environment.NewLine, StringComparison.CurrentCulture))
     {
         _endsWithNewline = true;
     }
     // This is an optimization. If the current indent is "", then we don't have to do any
     // of the more complex stuff further down.
     if (_currentIndent.Length == 0)
     {
         GenerationText.Append(textToAppend);
         return((T)this);
     }
     // Everywhere there is a newline in the text, add an indent after it
     textToAppend = textToAppend.Replace(Environment.NewLine, Environment.NewLine + _currentIndent);
     // If the text ends with a newline, then we should strip off the indent added at the very end
     // because the appropriate indent will be added when the next time Write() is called
     if (_endsWithNewline)
     {
         GenerationText.Append(textToAppend, 0, textToAppend.Length - _currentIndent.Length);
     }
     else
     {
         GenerationText.Append(textToAppend);
     }
     return((T)this);
 }
 public override string ToString()
 {
     return(GenerationText.ToString());
 }