Meziantou.Framework.FixedStringBuilder provides fixed-capacity string value types for low-allocation text operations.
The package includes the following types:
FixedStringBuilder8FixedStringBuilder16FixedStringBuilder32FixedStringBuilder64
using Meziantou.Framework.FixedStringBuilder;
FixedStringBuilder16 sb = $"Hello {"World"}";
sb.AppendLiteral("!");
string str = sb.ToString();If a value does not fit in the configured capacity, operations throw ArgumentException.
Clear() only resets the length: the characters stay in the underlying buffer. Use Clear(zeroBuffer: true) to also
overwrite the whole buffer with '\0'.
FixedStringBuilder16 sb = $"secret";
sb.Clear(zeroBuffer: true);The package Meziantou.Framework.FixedStringBuilder.Generator includes a source generator. Declare a partial struct with FixedStringBuilderAttribute:
using Meziantou.Framework.FixedStringBuilder;
[FixedStringBuilderAttribute(128)]
public partial struct FixedStringBuilder128;The generated struct supports the same APIs as the built-in types (Length, Clear, TryFormat, interpolation, equality, and conversions from string).