Minor tweaks for better Ignitor debugability (#22446)
This commit is contained in:
parent
bdc051a08a
commit
646dfc63e4
|
|
@ -11,5 +11,7 @@ namespace Ignitor
|
|||
{
|
||||
_componentId = componentId;
|
||||
}
|
||||
|
||||
public int ComponentId => _componentId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,16 @@
|
|||
|
||||
#nullable enable
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Ignitor
|
||||
{
|
||||
[DebuggerDisplay("{SerializedValue}")]
|
||||
public abstract class Node
|
||||
{
|
||||
public virtual ContainerNode? Parent { get; set; }
|
||||
|
||||
public string SerializedValue => NodeSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
#nullable enable
|
||||
|
|
@ -20,11 +21,22 @@ namespace Ignitor
|
|||
}
|
||||
}
|
||||
|
||||
public static string Serialize(Node node)
|
||||
{
|
||||
using (var writer = new StringWriter())
|
||||
{
|
||||
var serializer = new Serializer(writer);
|
||||
serializer.Serialize(node);
|
||||
return writer.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private class Serializer
|
||||
{
|
||||
private readonly TextWriter _writer;
|
||||
private int _depth;
|
||||
private bool _atStartOfLine;
|
||||
private HashSet<Node> _visited = new HashSet<Node>();
|
||||
|
||||
public Serializer(TextWriter writer)
|
||||
{
|
||||
|
|
@ -35,14 +47,25 @@ namespace Ignitor
|
|||
{
|
||||
foreach (var kvp in hive.Components)
|
||||
{
|
||||
SerializeComponent(kvp.Key, kvp.Value);
|
||||
Serialize(kvp.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private void Serialize(Node node)
|
||||
public void Serialize(Node node)
|
||||
{
|
||||
if (!_visited.Add(node))
|
||||
{
|
||||
// This is a child component of a previously seen component. Don't repeat it
|
||||
return;
|
||||
}
|
||||
|
||||
switch (node)
|
||||
{
|
||||
case ComponentNode componentNode:
|
||||
{
|
||||
SerializeComponent(componentNode);
|
||||
break;
|
||||
}
|
||||
case ElementNode elementNode:
|
||||
{
|
||||
SerializeElement(elementNode);
|
||||
|
|
@ -155,10 +178,10 @@ namespace Ignitor
|
|||
}
|
||||
}
|
||||
|
||||
private void SerializeComponent(int id, ComponentNode component)
|
||||
private void SerializeComponent(ComponentNode component)
|
||||
{
|
||||
Write("[Component ( ");
|
||||
Write(id.ToString());
|
||||
Write(component.ComponentId.ToString());
|
||||
WriteLine(" )]");
|
||||
_depth++;
|
||||
SerializeChildren(component);
|
||||
|
|
|
|||
Loading…
Reference in New Issue