- add function to convert enumberable to gBase string

pull/26/head
Simon Gockner 6 years ago
parent bb0652428c
commit 6aeffa85ee
  1. 32
      GBase/Helpers/Enumerables.cs

@ -0,0 +1,32 @@
// Author: Gockner, Simon
// Created: 2020-02-13
// Copyright(c) 2020 SimonG. All Rights Reserved.
using System.Collections;
using System.Text;
namespace GBase.Helpers
{
internal static class Enumerables
{
/// <summary>
/// Convert an <see cref="IEnumerable"/> to a GBase <see cref="string"/>
/// </summary>
/// <param name="enumerable">The <see cref="IEnumerable"/></param>
/// <returns></returns>
public static string ToGBaseString(this IEnumerable enumerable)
{
StringBuilder @string = new StringBuilder();
foreach (var item in enumerable)
{
@string.Append($"{item},");
}
char lastChar = @string[^1];
if (lastChar == ',')
@string.Remove(@string.Length - 1, 1);
return @string.ToString();
}
}
}
Loading…
Cancel
Save