2021-08-27 15:03:47 +00:00
|
|
|
using System.Collections.Generic;
|
2020-08-27 19:28:36 +00:00
|
|
|
|
|
|
|
using Serilog.Core;
|
|
|
|
using Serilog.Events;
|
|
|
|
|
|
|
|
namespace PluralKit.Core
|
|
|
|
{
|
|
|
|
public class PatchObjectDestructuring: IDestructuringPolicy
|
|
|
|
{
|
|
|
|
public bool TryDestructure(object value, ILogEventPropertyValueFactory factory,
|
|
|
|
out LogEventPropertyValue result)
|
|
|
|
{
|
|
|
|
result = null;
|
|
|
|
if (!(value is PatchObject po)) return false;
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2020-08-27 19:28:36 +00:00
|
|
|
var propList = new List<LogEventProperty>();
|
|
|
|
foreach (var props in po.GetType().GetProperties())
|
|
|
|
{
|
|
|
|
var propValue = props.GetValue(po);
|
|
|
|
if (propValue is IPartial p && p.IsPresent)
|
2020-08-28 09:37:53 +00:00
|
|
|
propList.Add(new LogEventProperty(props.Name, factory.CreatePropertyValue(p.RawValue, true)));
|
2020-08-27 19:28:36 +00:00
|
|
|
else if (!(propValue is IPartial))
|
2020-08-28 09:37:53 +00:00
|
|
|
propList.Add(new LogEventProperty(props.Name, factory.CreatePropertyValue(propValue, true)));
|
2020-08-27 19:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
result = new StructureValue(propList);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|