Skip to content

Commit 728aeb5

Browse files
committed
Feat: ForEachAppendBodyIndented
1 parent eef945c commit 728aeb5

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/CodeOfChaos.GeneratorTools/StringBuilders/GeneratorStringBuilder.cs

+26
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,32 @@ public GeneratorStringBuilder ForEachAppendBody<T>(IEnumerable<T> items, Func<T,
278278
items,
279279
itemFormatter: (g, item) => g.AppendBody(itemFormatter(item))
280280
);
281+
282+
283+
284+
/// <summary>
285+
/// Appends the content of each item in the provided enumerable to the builder
286+
/// by formatting them as body content as an indented body.
287+
/// </summary>
288+
/// <param name="items">The collection of strings to be appended as body content.</param>
289+
/// <returns>The current instance of <see cref="GeneratorStringBuilder" />, allowing for method chaining.</returns>
290+
public GeneratorStringBuilder ForEachAppendBodyIndented(IEnumerable<string> items) => ForEach(items, itemFormatter: (g, item) => g.AppendBodyIndented(item));
291+
292+
/// <summary>
293+
/// Iterates over the specified enumerable collection and appends the formatted body content for each item
294+
/// using the provided item formatter function an indented body.
295+
/// </summary>
296+
/// <typeparam name="T">The type of the items in the enumerable collection.</typeparam>
297+
/// <param name="items">The collection of items to iterate over.</param>
298+
/// <param name="itemFormatter">
299+
/// A function that formats each item into a string representation. This formatted value is appended as body content
300+
/// using <see cref="AppendBody" />.
301+
/// </param>
302+
/// <returns>The current instance of <see cref="GeneratorStringBuilder" />, allowing for method chaining.</returns>
303+
public GeneratorStringBuilder ForEachAppendBodyIndented<T>(IEnumerable<T> items, Func<T, string> itemFormatter) => ForEach(
304+
items,
305+
itemFormatter: (g, item) => g.AppendBodyIndented(itemFormatter(item))
306+
);
281307

282308
/// <summary>
283309
/// Iterates through a collection of items, applying a specified action for each item.

tests/Tests.CodeOfChaos.GeneratorTools/Tests.CodeOfChaos.GeneratorTools.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
</PackageReference>
1919
<PackageReference Include="Moq" Version="4.20.72"/>
20-
<PackageReference Include="TUnit" Version="0.6.51" />
20+
<PackageReference Include="TUnit" Version="0.6.52" />
2121
<PackageReference Include="Bogus" Version="35.6.1"/>
2222
</ItemGroup>
2323

0 commit comments

Comments
 (0)