/// <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(); }
/// <summary> /// Begin an indent scope. /// </summary> /// <param name="options"> /// Options for the scoped indent. /// </param> /// <returns> /// An <see cref="IDisposable"/> implementation which, when disposed, closes the indent scope. /// </returns> /// <remarks> /// Indent scopes are a simple way of making code that produces indented text easier to read. /// /// Use of C#'s <c>using</c> statement has a negligible performance impact if no exceptions are thrown, so feel free to use it wherever it makes sense. /// </remarks> public IDisposable BeginIndentScope(ScopedIndentOptions options = null) { return new IndentScope(this, options ?? ScopedIndentOptions.None); }