diff --git a/Utilities/DebugUtility.cs b/Utilities/DebugUtility.cs index 6337b32..0d999f1 100644 --- a/Utilities/DebugUtility.cs +++ b/Utilities/DebugUtility.cs @@ -66,7 +66,7 @@ public static T Dump(this T value, string name) /// /// Formats collections (and IEnumerables) in an array-like format. /// - public static string Format(object? value) + public static string Format(object? value, string separator = ", ", string prefix = "[", string suffix = "]") { if (value == null) { @@ -76,7 +76,7 @@ public static string Format(object? value) if (value is IEnumerable enumerable && value is not string) { var stringBuilder = new StringBuilder(); - FormatEnumerable(enumerable, stringBuilder); + FormatEnumerable(enumerable, stringBuilder, separator, prefix, suffix); return stringBuilder.ToString(); } @@ -84,9 +84,9 @@ public static string Format(object? value) return value.ToString() ?? "Null"; } - private static void FormatEnumerable(IEnumerable enumerable, StringBuilder stringBuilder) + private static void FormatEnumerable(IEnumerable enumerable, StringBuilder stringBuilder, string separator, string prefix, string suffix) { - stringBuilder.Append("["); + stringBuilder.Append(prefix); var isFirst = true; @@ -94,12 +94,12 @@ private static void FormatEnumerable(IEnumerable enumerable, StringBuilder strin { if (!isFirst) { - stringBuilder.Append(", "); + stringBuilder.Append(separator); } if (value is IEnumerable nestedEnumerable && value is not string) { - FormatEnumerable(nestedEnumerable, stringBuilder); + FormatEnumerable(nestedEnumerable, stringBuilder, separator, prefix, suffix); } else { @@ -109,7 +109,7 @@ private static void FormatEnumerable(IEnumerable enumerable, StringBuilder strin isFirst = false; } - stringBuilder.Append("]"); + stringBuilder.Append(suffix); } ///