48 lines
965 B
C#
48 lines
965 B
C#
using System;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
|
|
namespace srl.Debug;
|
|
|
|
public class DebugDriver : Driver
|
|
{
|
|
private StringBuilder _sb = new();
|
|
private int _indent = 0;
|
|
|
|
public override string ToString() => _sb.ToString();
|
|
|
|
private void Line( string s ) => _sb.AppendLine( new string( ' ', _indent * 2 ) + s );
|
|
|
|
public void BeginScope( string name, Type type, int id )
|
|
{
|
|
var refStr = id > 0 ? $" #{id}" : "";
|
|
Line( $"[{name}] <{type.Name}>{refStr}" );
|
|
_indent++;
|
|
}
|
|
|
|
public void EndScope() => _indent--;
|
|
|
|
public void BeginCollection( string name, int count )
|
|
{
|
|
Line( $"[{name}] (Count: {count})" );
|
|
_indent++;
|
|
}
|
|
|
|
public void EndCollection() => _indent--;
|
|
|
|
public void WriteAttr( string name, string value )
|
|
{
|
|
Line( $"{name} = {value}" );
|
|
}
|
|
|
|
public void WriteRef( string name, int id )
|
|
{
|
|
Line( $"{name} -> See #{id}" );
|
|
}
|
|
|
|
public void OnProp( MemberInfo m, string name )
|
|
{
|
|
// Could log attributes here, e.g. [Tooltip]
|
|
}
|
|
}
|