Skip to content

Commit c5ced3a

Browse files
committed
Added helper method for logging a collection in a list format.
1 parent d230807 commit c5ced3a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Runtime/DevConsole.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,19 @@ public static void LogSeperator(object message = null)
241241
_console.LogSeperator(message);
242242
}
243243

244+
/// <summary>
245+
/// Log a collection in list format.
246+
/// </summary>
247+
/// <typeparam name="T"></typeparam>
248+
/// <param name="collection"></param>
249+
/// <param name="toString"></param>
250+
/// <param name="prefix"></param>
251+
/// <param name="suffix"></param>
252+
public static void LogCollection<T>(in IReadOnlyCollection<T> collection, Func<T, string> toString = null, string prefix = "", string suffix = "")
253+
{
254+
_console.LogCollection(collection, toString, prefix, suffix);
255+
}
256+
244257
/// <summary>
245258
/// Log the most recently executed command syntax to the dev console.
246259
/// </summary>

Runtime/DevConsoleMono.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,19 @@ internal void LogSeperator(object message = null)
536536
Log($"- <b>{message}</b> -");
537537
}
538538

539+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
540+
internal void LogCollection<T>(in IReadOnlyCollection<T> collection, Func<T, string> toString = null, string prefix = "", string suffix = "")
541+
{
542+
if (collection == null || collection.Count == 0)
543+
{
544+
return;
545+
}
546+
547+
Log(string.Join("\n",
548+
collection.Select(x => $"{prefix}{toString?.Invoke(x) ?? x.ToString()}{suffix}"))
549+
);
550+
}
551+
539552
internal void LogCommand()
540553
{
541554
LogCommand(_currentCommand);

0 commit comments

Comments
 (0)