Update JsonDebugger.cs

This commit is contained in:
Mikhail 2026-04-08 14:50:30 +08:00
parent 1f263726f9
commit 04ba0a3549

View File

@ -11,7 +11,7 @@ namespace DCFApixels.DragonECS.Core.Internal
private readonly static List<string> _indentsChache = new List<string>(); private readonly static List<string> _indentsChache = new List<string>();
internal static string ToJsonLog(object obj) internal static string ToJsonLog(object obj)
{ {
if (obj == null) return "null"; if (obj == null) { return "null"; }
var sb = new StringBuilder(); var sb = new StringBuilder();
int linesCounter = 0; int linesCounter = 0;
var visited = new Dictionary<object, int>(); var visited = new Dictionary<object, int>();
@ -142,10 +142,10 @@ namespace DCFApixels.DragonECS.Core.Internal
return; return;
} }
if(value is Delegate del) if (value is Delegate del)
{ {
var list = del.GetInvocationList(); var list = del.GetInvocationList();
if(list.Length == 0) if (list.Length == 0)
{ {
sb.Append("null"); sb.Append("null");
return; return;
@ -159,13 +159,11 @@ namespace DCFApixels.DragonECS.Core.Internal
sb.Append('"'); sb.Append('"');
return; return;
} }
ToJsonLog(ref linesCounter, list, sb, visited, indent, indentStep);
value = list; return;
type = list.GetType();
// как дописать приваильно тут вызов ToJsonLog ?
} }
if(type.IsValueType == false) if (type.IsValueType == false)
{ {
if (visited.TryGetValue(value, out var line)) if (visited.TryGetValue(value, out var line))
{ {
@ -179,7 +177,7 @@ namespace DCFApixels.DragonECS.Core.Internal
visited.Add(value, linesCounter); visited.Add(value, linesCounter);
} }
// Collections
IEnumerable enumerable = value as IEnumerable; IEnumerable enumerable = value as IEnumerable;
if(enumerable != null) if(enumerable != null)
{ {
@ -206,7 +204,7 @@ namespace DCFApixels.DragonECS.Core.Internal
ToJsonLog(ref linesCounter, item, sb, visited, indent + 1, indentStep); ToJsonLog(ref linesCounter, item, sb, visited, indent + 1, indentStep);
} }
// Если были элементы, переносим строку перед закрывающей скобкой // перенос строки если были элементы
if (!first) if (!first)
{ {
NewLine(ref linesCounter, sb, indent, indentStep); NewLine(ref linesCounter, sb, indent, indentStep);
@ -230,8 +228,6 @@ namespace DCFApixels.DragonECS.Core.Internal
if (!first) { sb.Append(','); } else { first = false; } if (!first) { sb.Append(','); } else { first = false; }
NewLine(ref linesCounter, sb, indent + 1, indentStep); NewLine(ref linesCounter, sb, indent + 1, indentStep);
//sb.AppendLine();
//sb.Append(nextIndent);
sb.Append('"'); sb.Append('"');
sb.Append(field.Name); sb.Append(field.Name);
sb.Append('"'); sb.Append('"');
@ -272,7 +268,7 @@ namespace DCFApixels.DragonECS.Core.Internal
ToJsonLog(ref linesCounter, propValue, sb, visited, indent + 1, indentStep); ToJsonLog(ref linesCounter, propValue, sb, visited, indent + 1, indentStep);
} }
// Если были поля/свойства, добавляем перевод строки перед закрывающей скобкой // перенос строки если были элементы
if (!first) if (!first)
{ {
NewLine(ref linesCounter, sb, indent, indentStep); NewLine(ref linesCounter, sb, indent, indentStep);