Skip to content

Commit ff8b948

Browse files
committed
Added Append(Guid) overload
1 parent badb5c2 commit ff8b948

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
99
### Added
1010

1111
- `ToString(startIndex, length)` to get a substring from the builder
12+
- `Append(Guid guid)` as new overload
1213

1314
## [1.6.2] - 2022-11-11
1415

src/LinkDotNet.StringBuilder/ValueStringBuilder.Append.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ public ref partial struct ValueStringBuilder
7474
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7575
public void Append(decimal value) => AppendSpanFormattable(value);
7676

77+
/// <summary>
78+
/// Appends the string representation of the Guid to the builder.
79+
/// </summary>
80+
/// <param name="value">Guid to add.</param>
81+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
82+
public void Append(Guid value) => AppendSpanFormattable(value, "D");
83+
7784
/// <summary>
7885
/// Appends a string to the string builder.
7986
/// </summary>
@@ -112,11 +119,11 @@ public void AppendLine(scoped ReadOnlySpan<char> str)
112119
}
113120

114121
[MethodImpl(MethodImplOptions.AggressiveInlining)]
115-
private void AppendSpanFormattable<T>(T value)
122+
private void AppendSpanFormattable<T>(T value, ReadOnlySpan<char> format = default)
116123
where T : ISpanFormattable
117124
{
118-
Span<char> tempBuffer = stackalloc char[24];
119-
if (value.TryFormat(tempBuffer, out var written, default, null))
125+
Span<char> tempBuffer = stackalloc char[36];
126+
if (value.TryFormat(tempBuffer, out var written, format, null))
120127
{
121128
var newSize = written + bufferPosition;
122129
if (newSize >= buffer.Length)

tests/LinkDotNet.StringBuilder.UnitTests/ValueStringBuilder.Append.Tests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,14 @@ public void ShouldAppendMultipleDoubles()
201201

202202
builder.ToString().Should().Be("0.33333333333333330.33333333333333330.3333333333333333");
203203
}
204+
205+
[Fact]
206+
public void ShouldAppendGuid()
207+
{
208+
using var builder = new ValueStringBuilder();
209+
210+
builder.Append(Guid.Empty);
211+
212+
builder.ToString().Should().Be("00000000-0000-0000-0000-000000000000");
213+
}
204214
}

0 commit comments

Comments
 (0)