From 12e58ef2732a2676f9d01d81bc789be697d1e5de Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:03:51 +0800 Subject: [PATCH] update debug utils --- src/DebugUtils/EcsDebug.cs | 18 ++++++++++++++++-- src/DebugUtils/EcsDebugUtility.cs | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/DebugUtils/EcsDebug.cs b/src/DebugUtils/EcsDebug.cs index 6742a91..91bdd20 100644 --- a/src/DebugUtils/EcsDebug.cs +++ b/src/DebugUtils/EcsDebug.cs @@ -1,5 +1,6 @@ using DCFApixels.DragonECS.Internal; using System; +using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; @@ -134,6 +135,19 @@ namespace DCFApixels.DragonECS } } + protected static string AutoConvertObjectToString(object o) + { + if (o is string str) + { + return str; + } + if (o is IEnumerable enumerable) + { + return string.Join(", ", enumerable.Cast()); + } + return o.ToString(); + } + public readonly struct MarkerInfo { public readonly string Name; @@ -281,7 +295,7 @@ namespace DCFApixels.DragonECS { if (string.IsNullOrEmpty(tag)) { - Console.WriteLine(v); + Console.WriteLine(AutoConvertObjectToString(v)); } else { @@ -298,7 +312,7 @@ namespace DCFApixels.DragonECS Console.ForegroundColor = ConsoleColor.Green; break; } - Console.WriteLine($"[{tag}] {v}"); + Console.WriteLine($"[{tag}] {AutoConvertObjectToString(v)}"); Console.ForegroundColor = color; } } diff --git a/src/DebugUtils/EcsDebugUtility.cs b/src/DebugUtils/EcsDebugUtility.cs index 93ebdcb..66cfae5 100644 --- a/src/DebugUtils/EcsDebugUtility.cs +++ b/src/DebugUtils/EcsDebugUtility.cs @@ -66,7 +66,7 @@ namespace DCFApixels.DragonECS return AutoToString(self, typeof(T), isWriteName); } - private static string AutoToString(object target, Type type, bool isWriteName) + internal static string AutoToString(object target, Type type, bool isWriteName) { #if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает #pragma warning disable IL2070 // 'this' argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The parameter of method does not have matching annotations.