Class StringMaker
- Namespace
- Switchboard
- Assembly
- Switchboard.StringMaker.dll
Represents a string of characters that can be modified without allocating memory for garbage collection.
public sealed class StringMaker
- Inheritance
-
StringMaker
- Extension Methods
Fields
ArrayLength
Gets the number of characters that can be stored in each character array that StringMaker links together in internal memory. Memory is allocated and pooled internally as character arrays of this length.
public const int ArrayLength = 1024
Properties
AppendAction
Gets the static ReadOnlySpanAction<T, TArg> instance used to append a character Span<T> to a StringMaker.
public static ReadOnlySpanAction<char, StringMaker> AppendAction { get; }
ArrayPoolCount
Gets the number of character arrays stored in the shared pool. May not be perfectly accurate while other threads are modifying the pool.
public static int ArrayPoolCount { get; }
ArrayPoolMaxCount
Gets the maximum number of character arrays that can be stored in the shared pool.
public static int ArrayPoolMaxCount { get; }
CopyAction
Gets the static SpanAction<T, TArg> instance used to copy the contents of a StringMaker to a character Span<T>.
public static SpanAction<char, StringMaker> CopyAction { get; }
Length
Gets or sets the current character count, the number of characters that will be copied during operations like ToString() or CopyTo(Span<char>).
public int Length { get; set; }
Exceptions
- ArgumentOutOfRangeException
Thrown if the set value is less than zero.
NumberFormat
Gets or sets the FloatFormatInfo used to format number values.
public FloatFormatInfo NumberFormat { get; set; }
Shared
Gets a ThreadStaticAttribute instance of the class.
public static StringMaker Shared { get; }
Methods
Append(bool)
Appends a boolean value.
public StringMaker Append(bool value)
Parameters
value
boolThe boolean value to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Append(char)
Appends a character.
public StringMaker Append(char value)
Parameters
value
charThe character to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Append(char, int)
Appends a repeating character.
public StringMaker Append(char value, int count)
Parameters
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Append(DateTime)
Appends a DateTime.
public StringMaker Append(DateTime value)
Parameters
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Append(DateTime, int)
Appends a DateTime.
public StringMaker Append(DateTime value, int subSecondPrecision)
Parameters
value
DateTimeThe DateTime to append.
subSecondPrecision
intThe number of digits to display for fractions of a second.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Append(double)
Appends a double-precision floating-point number.
public StringMaker Append(double value)
Parameters
value
doubleThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Append(double, FloatFormatInfo)
Appends a double-precision floating-point number.
public StringMaker Append(double value, FloatFormatInfo format)
Parameters
value
doubleThe number to append.
format
FloatFormatInfoDetailed settings for formatting the result.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Append(double, int)
Appends a double-precision floating-point number.
public StringMaker Append(double value, int minFractionalDigits)
Parameters
value
doubleThe number to append.
minFractionalDigits
intThe minimum number of fractional digits to display.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Exceptions
- ArgumentOutOfRangeException
Thrown if
minFractionalDigits
is less than zero.
Append(double, int, int)
Appends a double-precision floating-point number.
public StringMaker Append(double value, int minFractionalDigits, int maxFractionalDigits)
Parameters
value
doubleThe number to append.
minFractionalDigits
intThe minimum number of fractional digits to display.
maxFractionalDigits
intThe maximum number of fractional digits to display.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Exceptions
- ArgumentOutOfRangeException
Thrown if
minFractionalDigits
ormaxFractionalDigits
are less than zero, or ifminFractionalDigits
is greater thanmaxFractionalDigits
.
Append(double, int, int, bool)
Appends a double-precision floating-point number.
public StringMaker Append(double value, int minFractionalDigits, int maxFractionalDigits, bool groupDigits)
Parameters
value
doubleThe number to append.
minFractionalDigits
intThe minimum number of fractional digits to display.
maxFractionalDigits
intThe maximum number of fractional digits to display.
groupDigits
boolWhether to separate digit groups with a comma.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Exceptions
- ArgumentOutOfRangeException
Thrown if
minFractionalDigits
ormaxFractionalDigits
are less than zero, or ifminFractionalDigits
is greater thanmaxFractionalDigits
.
Append(long)
Appends a long integer.
public StringMaker Append(long value)
Parameters
value
longThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Append(long, char)
Appends a long integer.
public StringMaker Append(long value, char digitGroupSeparator)
Parameters
value
longThe number to append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Append(ReadOnlySpan<char>)
Appends a ReadOnlySpan<T> of characters.
public StringMaker Append(ReadOnlySpan<char> value)
Parameters
value
ReadOnlySpan<char>The ReadOnlySpan<T> of characters to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Append(ulong)
Appends an unsinged long integer.
public StringMaker Append(ulong value)
Parameters
value
ulongThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Append(ulong, char)
Appends an unsinged long integer.
public StringMaker Append(ulong value, char digitGroupSeparator)
Parameters
value
ulongThe number to append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(byte)
Appends a byte as a binary value.
public StringMaker AppendBinary(byte value)
Parameters
value
byteThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(short)
Appends a short integer as a binary value.
public StringMaker AppendBinary(short value)
Parameters
value
shortThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(short, char)
Appends a short integer as a binary value.
public StringMaker AppendBinary(short value, char digitGroupSeparator)
Parameters
value
shortThe numberto append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(int)
Appends an integer as a binary value.
public StringMaker AppendBinary(int value)
Parameters
value
intThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(int, char)
Appends an integer as a binary value.
public StringMaker AppendBinary(int value, char digitGroupSeparator)
Parameters
value
intThe number to append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(long)
Appends a long integer as a binary value.
public StringMaker AppendBinary(long value)
Parameters
value
longThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(long, char)
Appends a long integer as a binary value.
public StringMaker AppendBinary(long value, char digitGroupSeparator)
Parameters
value
longThe number to append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(sbyte)
Appends a signed byte as a binary value.
public StringMaker AppendBinary(sbyte value)
Parameters
value
sbyteThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(ushort)
Appends an unsigned short integer as a binary value.
public StringMaker AppendBinary(ushort value)
Parameters
value
ushortThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(ushort, char)
Appends an unsigned short integer as a binary value.
public StringMaker AppendBinary(ushort value, char digitGroupSeparator)
Parameters
value
ushortThe number to append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(uint)
Appends an unsigned integer as a binary value.
public StringMaker AppendBinary(uint value)
Parameters
value
uintThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(uint, char)
Appends an unsigned integer as a binary value.
public StringMaker AppendBinary(uint value, char digitGroupSeparator)
Parameters
value
uintThe number to append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(ulong)
Appends an unsigned long integer as a binary value.
public StringMaker AppendBinary(ulong value)
Parameters
value
ulongThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendBinary(ulong, char)
Appends an unsigned long integer as a binary value.
public StringMaker AppendBinary(ulong value, char digitGroupSeparator)
Parameters
value
ulongThe number to append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(byte)
Appends a byte as a hexadecimal value.
public StringMaker AppendHexadecimal(byte value)
Parameters
value
byteThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(short)
Appends a short integer as a hexadecimal value.
public StringMaker AppendHexadecimal(short value)
Parameters
value
shortThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(short, char)
Appends a short integer as a hexadecimal value.
public StringMaker AppendHexadecimal(short value, char digitGroupSeparator)
Parameters
value
shortThe number to append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(int)
Appends an integer as a hexadecimal value.
public StringMaker AppendHexadecimal(int value)
Parameters
value
intThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(int, char)
Appends an integer as a hexadecimal value.
public StringMaker AppendHexadecimal(int value, char digitGroupSeparator)
Parameters
value
intThe number to append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(long)
Appends a long integer as a hexadecimal value.
public StringMaker AppendHexadecimal(long value)
Parameters
value
longThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(long, char)
Appends a long integer as a hexadecimal value.
public StringMaker AppendHexadecimal(long value, char digitGroupSeparator)
Parameters
value
longThe number to append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(sbyte)
Appends a signed byte as a hexadecimal value.
public StringMaker AppendHexadecimal(sbyte value)
Parameters
value
sbyteThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(ushort)
Appends an unsigned short integer as a hexadecimal value.
public StringMaker AppendHexadecimal(ushort value)
Parameters
value
ushortThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(ushort, char)
Appends an unsigned short integer as a hexadecimal value.
public StringMaker AppendHexadecimal(ushort value, char digitGroupSeparator)
Parameters
value
ushortThe number to append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(uint)
Appends an unsigned integer.
public StringMaker AppendHexadecimal(uint value)
Parameters
value
uintThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(uint, char)
Appends an unsigned integer as a hexadecimal value.
public StringMaker AppendHexadecimal(uint value, char digitGroupSeparator)
Parameters
value
uintThe number to append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(ulong)
Appends an unsigned long integer as a hexadecimal value.
public StringMaker AppendHexadecimal(ulong value)
Parameters
value
ulongThe number to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
AppendHexadecimal(ulong, char)
Appends an unsigned long integer as a hexadecimal value.
public StringMaker AppendHexadecimal(ulong value, char digitGroupSeparator)
Parameters
value
ulongThe number to append.
digitGroupSeparator
charThe character to use for separating groups of digits.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Clear()
Sets the Length to zero.
public StringMaker Clear()
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Clear(FloatFormatInfo)
Sets the Length to zero, and sets the NumberFormat.
public StringMaker Clear(FloatFormatInfo numberFormat)
Parameters
numberFormat
FloatFormatInfo
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
ConvertToUTF8(Span<byte>)
Converts the contents of the instance to a UTF-8 byte Span<T>.
public int ConvertToUTF8(Span<byte> target)
Parameters
Returns
- int
The number of bytes copied to the
target
.
Exceptions
- ArgumentException
Thrown if the
target
length is less than the StringMaker Length.
CopyTo(Span<char>)
Copies the contents of the instance to a character Span<T>.
public void CopyTo(Span<char> target)
Parameters
target
Span<char>The target character Span<T> to which the contents of this StringMaker will be copied.
Exceptions
- ArgumentException
Thrown if the
target
length is less than this StringMaker Length.
Equals(StringMaker)
Compares the characters of two StringMaker instances up to the current Length.
public bool Equals(StringMaker stringMaker)
Parameters
stringMaker
StringMakerThe other StringMaker to compare.
Returns
Equals(ReadOnlySpan<char>)
Compares the characters of a StringMaker to a ReadOnlySpan of characters up to the current Length.
public bool Equals(ReadOnlySpan<char> span)
Parameters
span
ReadOnlySpan<char>The ReadOnlySpan of characters to compare.
Returns
ForEachArray<T>(T, ForEachArrayAction<T>)
Invokes a StringMaker.ForEachArrayAction<TArg> for each character array in the StringMaker.
public void ForEachArray<T>(T arg, StringMaker.ForEachArrayAction<T> action)
Parameters
arg
TThe argument to pass into the action.
action
StringMaker.ForEachArrayAction<T>The action to invoke.
Type Parameters
T
The type of argument to be passed into the action.
ReleaseMemory()
Clears and releases excess character arrays to the shared pool. Also sets the null '\0' character from the Length index to the end of the current character array.
public StringMaker ReleaseMemory()
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
Reset()
Sets the Length to zero, and clear the NumberFormat.
public StringMaker Reset()
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
SetArrayPoolMaxCount(int)
Sets the maximum number of character arrays that can be stored in the shared pool.
public static void SetArrayPoolMaxCount(int maxCount)
Parameters
maxCount
intThe maximum number of character arrays that can be stored.
Exceptions
- ArgumentOutOfRangeException
Thrown if
maxCount
is less than zero.
ToString()
Allocates a new string and copies the contents of the StringMaker.
public override string ToString()
Returns
- string
The new string.
Operators
operator +(StringMaker, bool)
Appends a value.
public static StringMaker operator +(StringMaker stringMaker, bool value)
Parameters
stringMaker
StringMakerThe StringMaker to append.
value
boolThe value to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
operator +(StringMaker, char)
Appends a value.
public static StringMaker operator +(StringMaker stringMaker, char value)
Parameters
stringMaker
StringMakerThe StringMaker to append.
value
charThe value to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
operator +(StringMaker, DateTime)
Appends a value.
public static StringMaker operator +(StringMaker stringMaker, DateTime value)
Parameters
stringMaker
StringMakerThe StringMaker to append.
value
DateTimeThe value to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
operator +(StringMaker, double)
Appends a value.
public static StringMaker operator +(StringMaker stringMaker, double value)
Parameters
stringMaker
StringMakerThe StringMaker to append.
value
doubleThe value to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
operator +(StringMaker, long)
Appends a value.
public static StringMaker operator +(StringMaker stringMaker, long value)
Parameters
stringMaker
StringMakerThe StringMaker to append.
value
longThe value to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
operator +(StringMaker, ReadOnlySpan<char>)
Appends a value.
public static StringMaker operator +(StringMaker stringMaker, ReadOnlySpan<char> value)
Parameters
stringMaker
StringMakerThe StringMaker to append.
value
ReadOnlySpan<char>The value to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.
operator +(StringMaker, ulong)
Appends a value.
public static StringMaker operator +(StringMaker stringMaker, ulong value)
Parameters
stringMaker
StringMakerThe StringMaker to append.
value
ulongThe value to append.
Returns
- StringMaker
Returns the instance, enabling a fluent interface.