forked from amkovkov/GranuSightSoftware2
31 lines
1.3 KiB
C#
31 lines
1.3 KiB
C#
using System.Collections;
|
|
|
|
namespace GSS2.Core.Extentions;
|
|
|
|
public static class EnumerableExtensions
|
|
{
|
|
public static IEnumerable<(int i, T value)> Enumerate<T>(this IEnumerable<T> values) => values.Select((value, i) => (i, value));
|
|
|
|
public static string ToString<TKey, TValue>(this IDictionary<TKey, TValue> values, string separator, int indent) => string.Join(separator, values.Select(v => $"{new string(' ', indent)} {v.Key}: {v.Value}"));
|
|
public static string ToString(this IDictionary values, string separator, int indent)
|
|
{
|
|
var strs = new List<string?>();
|
|
var enumerator = values.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
strs.Add($"{enumerator.Key}: {enumerator.Value}");
|
|
return string.Join(separator, strs.Select(s => $"{new string(' ', indent)}{s}"));
|
|
}
|
|
|
|
public static string ToString<TValue>(this IEnumerable<TValue> values, string separator, int indent) => (values as IEnumerable).ToString(separator, indent);
|
|
public static string ToString(this IEnumerable values, string separator, int indent)
|
|
{
|
|
var strs = new List<string?>();
|
|
var enumerator = values.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
strs.Add(enumerator.Current.ToString());
|
|
return string.Join(separator, strs.Select(s => $"{new string(' ', indent)}{s}"));
|
|
}
|
|
|
|
}
|
|
|