Jwshyns.IndNet 1.0.1

dotnet add package Jwshyns.IndNet --version 1.0.1
NuGet\Install-Package Jwshyns.IndNet -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Jwshyns.IndNet" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Jwshyns.IndNet --version 1.0.1
#r "nuget: Jwshyns.IndNet, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Jwshyns.IndNet as a Cake Addin
#addin nuget:?package=Jwshyns.IndNet&version=1.0.1

// Install Jwshyns.IndNet as a Cake Tool
#tool nuget:?package=Jwshyns.IndNet&version=1.0.1

IndNet

A thin wrapper around StringBuilder to aid in indenting new lines when string building.


Configuration

Default constructor

var isb = new IndentedStringBuilder(indentationChar: '\t', startingIndentationLevel: 0, indentSize: 1, stringBuilder: null);
indentationChar
  • Defaults to \t
  • Optionally change the character used for indentation
startingIndentationLevel
  • Defaults to 0
  • Optionally change the starting indentation level
indentSize
  • Defaults to 1
  • Optionally change how many characters are used for each indentation level
stringBuilder
  • Defaults to null
  • Optionally provide a pre-configured StringBuilder

Example(s)

Using the IndentedStringBuilder is as easy as using the native StringBuilder, and exposes many of the same methods with the addition of the following:

IncrementIndentation(int amount = 1)

This method is used for incrementing the indentation of subsequently appended lines:

var isb = new IndentedStringBuilder();

var s = isb.AppendLine("Line 1")
            .IncrementIndentation()
            .AppendLine("Line 2")
            .ToString();

Console.WriteLine(s);

which would write the following to console:

Line 1
    Line 2

DecrementIndentation(int amount = 1)

This method is used for incrementing the indentation of subsequently appended lines:

var isb = new IndentedStringBuilder();

var s = isb.AppendLine("Line 1")
            .IncrementIndentation()
            .AppendLine("Line 2")
            .DecrementIndentation()
            .AppendLine("Line 3")
            .ToString();

Console.WriteLine(s);

which would write the following to console:

Line 1
    Line 2
Line 3

AppendLine(string? value)

Ok, StringBuilder has this too but in IndentedStringBuilder this behaves a bit differently. If you read the examples for IncrementIndentation and DecrementIndentation you'll see that in addition to appending new lines, it does so with respect to the current indentation of the IndentedStringBuilder (so have a look there for some usage examples).

AppendLines(int amount = 1)

This method wraps StringBuilder.AppendLine() allowing for you to append multiple blank lines from a single method call.

AppendLines(IEnumerable<string> values)

This method wraps AppendLine(string? value) allowing you to provide multiple strings and have them appended as new lines with respect to the current indentation level:

var isb = new IndentedStringBuilder();

var s = isb.AppendLine("Line 1")
            .IncrementIndentation()
            .AppendLines(new [] {"Line 2", "Line 3"})
            .ToString();

Console.WriteLine(s);

which would write the following to console:

Line 1
    Line 2
    Line 3

AppendBlock(Action<IIndentedStringBuilder> action)

This serves as a 'convenience' allowing another method to append to the builder whilst maintaining your call chaining:

var isb = new IndentedStringBuilder();

// can be a anonymous method, local method, class method, or other - this is just an example
Action<IIndentedStringBuilder> action = builder => { builder.AppendLines(new[] { "1", "2", "3" }); };

var s = isb.AppendLine("Line 1")
            .IncrementIndentation()
            .AppendBlock(action)
            .AppendLines(new [] {"Line 2", "Line 3"})
            .ToString();

Console.WriteLine(s);

which would write the following to console:

Line 1
    1
    2
    3
    Line 2
    Line 3

AppendIndentedBlock(Action<IIndentedStringBuilder> action)

Similar to AppendBlock(Action<IIndentedStringBuilder> action), this serves as a 'convenience' allowing another method to append to the builder whilst maintaining your call chaining, however this automatically increments and then decrements around the lines appended by the provided action:

var isb = new IndentedStringBuilder();

// can be a anonymous method, local method, class method, or other - this is just an example
Action<IIndentedStringBuilder> action = builder => { builder.AppendLines(new[] { "1", "2", "3" }); };

var s = isb.AppendLine("Line 1")
            .AppendIndentedBlock(action)
            .AppendLines(new [] {"Line 2", "Line 3"})
            .ToString();

Console.WriteLine(s);

which would write the following to console:

Line 1
    1
    2
    3
Line 2
Line 3

IndentAndAppendLines(IEnumerable<string> values)

Similar to AppendBlock(Action<IIndentedStringBuilder> action), however this allows you to provide strings that you wish to both indent and append as new lines:

var isb = new IndentedStringBuilder();


var s = isb.AppendLine("Line 1")
            .IndentAndAppendLines(new[] { "1", "2", "3" }))
            .AppendLines(new [] {"Line 2", "Line 3"})
            .ToString();

Console.WriteLine(s);

which would write the following to console:

Line 1
    1
    2
    3
Line 2
Line 3
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 195 11/9/2023
1.0.0 79 11/5/2023