/// <summary> /// Close the indent scope. /// </summary> public void Dispose() { if (_writer == null) return; if (_options.ScopePostfixNewLines.HasFlag(NewLines.Before)) _writer.WriteLine(); _writer.Unindent(); if (!String.IsNullOrWhiteSpace(_options.ScopePostfix)) { if (_options.ScopePostfixNewLines.HasFlag(NewLines.After)) _writer.WriteLine(_options.ScopePostfix); else _writer.Write(_options.ScopePostfix); } else if (_options.ScopePostfixNewLines.HasFlag(NewLines.After)) _writer.WriteLine(); _writer = null; }
/// <summary> /// Create a new indent scope. /// </summary> /// <param name="writer"> /// The indented string writer to which the indent scope applies. /// </param> /// <param name="options"> /// Options for the scoped indent. /// </param> public IndentScope(IndentedStringWriter writer, ScopedIndentOptions options) : this() { if (writer == null) throw new ArgumentNullException(nameof(writer)); if (options == null) throw new ArgumentNullException(nameof(options)); _writer = writer; _options = options; if (!String.IsNullOrWhiteSpace(_options.ScopePrefix)) { if (_options.ScopePrefixNewLines.HasFlag(NewLines.Before)) _writer.WriteLine(_options.ScopePrefix); else _writer.Write(_options.ScopePrefix); } else if (_options.ScopePrefixNewLines.HasFlag(NewLines.Before)) _writer.WriteLine(); _writer.Indent(); if (_options.ScopePrefixNewLines.HasFlag(NewLines.After)) _writer.WriteLine(); }