Skip to content

Commit 0bca3d7

Browse files
committed
Added helper methods
1 parent 46b3ac3 commit 0bca3d7

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
77
## [Unreleased]
88

99
### Added
10+
- New easy API for concatenating smaller strings or objects via `ValueStringBuilder.Concat("Hello", " ", "World");`
1011
- Smaller performance improvements in internal API's
1112

1213
## [1.4.1] - 2022-11-04
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace LinkDotNet.StringBuilder;
2+
3+
public ref partial struct ValueStringBuilder
4+
{
5+
/// <summary>
6+
/// Concatenates multiple objects together.
7+
/// </summary>
8+
/// <param name="values">Values, which will be concatenated together.</param>
9+
/// <typeparam name="T">Any given type, which can be translated to string.</typeparam>
10+
/// <returns>Concatenated string or an empty string if <see cref="values"/> is empty.</returns>
11+
public static string Concat<T>(params T[] values)
12+
{
13+
if (values.Length == 0)
14+
{
15+
return string.Empty;
16+
}
17+
18+
using var sb = new ValueStringBuilder();
19+
sb.AppendJoin(string.Empty, values);
20+
return sb.ToString();
21+
}
22+
}

tests/LinkDotNet.StringBuilder.UnitTests/ValueStringBuilderTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,12 @@ public void ShouldReturnRentedArrayBuffer()
344344

345345
builder.Dispose();
346346
}
347+
348+
[Fact]
349+
public void ShouldConcatStringsTogether()
350+
{
351+
var result = ValueStringBuilder.Concat("Hello", " ", "World");
352+
353+
result.Should().Be("Hello World");
354+
}
347355
}

0 commit comments

Comments
 (0)