reflection-based field logger for req/res msgs

This commit is contained in:
Kyle873
2024-12-21 23:45:36 -05:00
parent 3fa3915c2b
commit e2f0807ab1

View File

@@ -0,0 +1,30 @@
using Google.Protobuf;
using System.Reflection;
namespace EpinelPS.Utils
{
public static class LogUtils
{
public static void LogMessageFields(IMessage message)
{
Type type = message.GetType();
FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(type.Name + ":");
foreach (FieldInfo field in fields)
{
if (field.Name.ToLower().Contains("unknown"))
continue;
object? value = field.GetValue(message);
Console.WriteLine($"\t{field.Name}: {value}");
}
Console.ResetColor();
}
}
}