ValueStringBuilder Struct

  • Obsolete: Types with embedded references are not supported in this version of your compiler.
[Obsolete("Types with embedded references are not supported in this version of your compiler.", true)]
public ref struct ValueStringBuilder

No documentation is available.

Nested types

NameDescription
ValueStringBuilder.AppendInterpolatedStringHandler

Constructors

NameDescription
ValueStringBuilder(int)Initializes a builder backed by a buffer of at least initialCapacity characters rented from ArrayPool<T>.
ValueStringBuilder(Span<char>)Initializes a builder that writes into initialBuffer and only rents from ArrayPool<T> once the content outgrows it.

ValueStringBuilder overloads

ValueStringBuilder(int)

ValueStringBuilder.cs

Initializes a builder backed by a buffer of at least initialCapacity characters rented from ArrayPool<T>.

public ValueStringBuilder(int initialCapacity)
Parameters
initialCapacity int
The minimum number of characters the buffer must hold.

ValueStringBuilder(Span<char>)

ValueStringBuilder.cs

Initializes a builder that writes into initialBuffer and only rents from ArrayPool<T> once the content outgrows it.

public ValueStringBuilder(Span<char> initialBuffer)
Parameters
initialBuffer Span<char>
The buffer to write into, typically stack-allocated.

Properties

NameDescription
CapacityGets the number of characters the current buffer can hold before it has to grow.
LengthGets or sets the number of characters written so far. Setting it truncates the content, or exposes characters already present in the buffer when it is increased.
RawCharsGets the whole buffer, including the part past ValueStringBuilder.Length.

Gets the number of characters the current buffer can hold before it has to grow.

public readonly int Capacity { get; }

Property value

int

Gets or sets the number of characters written so far. Setting it truncates the content, or exposes characters already present in the buffer when it is increased.

public int Length { readonly get; set; }

Property value

int

Gets the whole buffer, including the part past ValueStringBuilder.Length.

public readonly Span<char> RawChars { get; }

Property value

Span<char>

Remarks

Everything beyond ValueStringBuilder.Length is uninitialized pooled memory and may hold data left by a previous user of the array. Use ValueStringBuilder.AsSpan to read only what was written.

Indexers

NameDescription
this[int]Gets a reference to the character at index, which can be used to overwrite it.

Gets a reference to the character at index, which can be used to overwrite it.

public ref char this[int index] { get; }

Parameters

index int
The position of the character, which must be less than ValueStringBuilder.Length.

Property value

char

Methods

NameDescription
Append(ValueStringBuilder.AppendInterpolatedStringHandler)
Append(char)Appends a single character.
Append(char, int)Appends c count times.
Append(IFormatProvider?, ValueStringBuilder.AppendInterpolatedStringHandler)
Append(ReadOnlySpan<char>)Appends the characters of value.
Append(string?)Appends a string. A null string is ignored.
Append(Rune)Appends a Unicode scalar value, encoded as one character or as a surrogate pair.
AppendSpan(int)Reserves length characters at the end of the content and returns them so the caller can write into the buffer directly. ValueStringBuilder.Length is advanced immediately, so the reserved characters are part of the content whether or not they are written to.
AppendSpanFormattable<T>(T, string?, IFormatProvider?)Appends value by formatting it straight into the buffer, falling back to IFormattable.ToString when it does not fit.
AsSpan()Returns the characters written so far, without disposing the builder.
AsSpan(int)Returns the characters written so far from start onwards.
AsSpan(int, int)Returns length characters starting at start.
Clear()Resets ValueStringBuilder.Length to 0, keeping the current buffer. The characters are not erased and stay readable through ValueStringBuilder.RawChars.
Dispose()Releases the buffer back to ArrayPool<T> and resets the builder. Calling it more than once is safe.
EnsureCapacity(int)Grows the buffer so that it can hold at least capacity characters.
GetPinnableReference()Returns a reference to the first character of the buffer, so the builder can be used with a fixed statement. The result is not null-terminated unless ValueStringBuilder.NullTerminate was called.
Insert(int, char, int)Inserts value count times at index.
Insert(int, string?)Inserts s at index. A null string is ignored.
NullTerminate()Writes a null character after the content, growing the buffer if needed, without changing ValueStringBuilder.Length.
ToString()Returns the characters written so far and disposes this instance, returning the rented buffer to the pool.

Append overloads

Append(ValueStringBuilder.AppendInterpolatedStringHandler)

ValueStringBuilder.AppendInterpolatedStringHandler.cs

No documentation is available.

Appends a single character.

public void Append(char c)
Parameters
c char
The character to append.

Append(char, int)

ValueStringBuilder.cs

Appends c count times.

public void Append(char c, int count)
Parameters
c char
The character to append.
count int
The number of times to append it.

Append(IFormatProvider?, ValueStringBuilder.AppendInterpolatedStringHandler)

ValueStringBuilder.AppendInterpolatedStringHandler.cs

No documentation is available.

Append(ReadOnlySpan<char>)

ValueStringBuilder.cs

Appends the characters of value.

public void Append(ReadOnlySpan<char> value)
Parameters
value ReadOnlySpan<char>
The characters to append.

Append(string?)

ValueStringBuilder.cs

Appends a string. A null string is ignored.

public void Append(string? s)
Parameters
s string?
The string to append.

Appends a Unicode scalar value, encoded as one character or as a surrogate pair.

public void Append(Rune rune)
Parameters
rune Rune
The scalar value to append.

AppendSpan(int)

ValueStringBuilder.cs

Reserves length characters at the end of the content and returns them so the caller can write into the buffer directly. ValueStringBuilder.Length is advanced immediately, so the reserved characters are part of the content whether or not they are written to.

public Span<char> AppendSpan(int length)

Parameters

length int
The number of characters to reserve.

Returns

Span<char>

AppendSpanFormattable<T>(T, string?, IFormatProvider?)

ValueStringBuilder.AppendSpanFormattable.cs

Appends value by formatting it straight into the buffer, falling back to IFormattable.ToString when it does not fit.

public void AppendSpanFormattable<T>(T value, string? format = null, IFormatProvider? provider = null) where T : ISpanFormattable

Type parameters

T

Parameters

value T
The value to append.
format string?
The format to use, or null for the default format.
provider IFormatProvider?
The provider to use, or null for the current culture.

AsSpan overloads

Returns the characters written so far, without disposing the builder.

public readonly ReadOnlySpan<char> AsSpan()

Returns the characters written so far from start onwards.

public readonly ReadOnlySpan<char> AsSpan(int start)
Parameters
start int
The position to start at.
Returns

ReadOnlySpan<char>

AsSpan(int, int)

ValueStringBuilder.cs

Returns length characters starting at start.

public readonly ReadOnlySpan<char> AsSpan(int start, int length)
Parameters
start int
The position to start at.
length int
The number of characters to return.
Returns

ReadOnlySpan<char>

Resets ValueStringBuilder.Length to 0, keeping the current buffer. The characters are not erased and stay readable through ValueStringBuilder.RawChars.

public void Clear()

Releases the buffer back to ArrayPool<T> and resets the builder. Calling it more than once is safe.

public void Dispose()

Remarks

The content is not erased; it stays readable by the next consumer to rent the array.

EnsureCapacity(int)

ValueStringBuilder.cs

Grows the buffer so that it can hold at least capacity characters.

public void EnsureCapacity(int capacity)

Parameters

capacity int
The minimum capacity required.

GetPinnableReference()

ValueStringBuilder.cs

Returns a reference to the first character of the buffer, so the builder can be used with a fixed statement. The result is not null-terminated unless ValueStringBuilder.NullTerminate was called.

public ref char GetPinnableReference()

Returns

char

Insert overloads

Insert(int, char, int)

ValueStringBuilder.cs

Inserts value count times at index.

public void Insert(int index, char value, int count)
Parameters
index int
The position to insert at.
value char
The character to insert.
count int
The number of times to insert it.

Insert(int, string?)

ValueStringBuilder.cs

Inserts s at index. A null string is ignored.

public void Insert(int index, string? s)
Parameters
index int
The position to insert at.
s string?
The string to insert.

NullTerminate()

ValueStringBuilder.cs

Writes a null character after the content, growing the buffer if needed, without changing ValueStringBuilder.Length.

public void NullTerminate()

Returns the characters written so far and disposes this instance, returning the rented buffer to the pool.

public override string ToString()

Returns

string

Remarks

This method is destructive. After it returns, the builder is reset to its default state: ValueStringBuilder.Length and ValueStringBuilder.Capacity are 0, a second call returns an empty string, and appending starts a new buffer. Use ValueStringBuilder.AsSpan to read the content without disposing the builder.