chore: depth limit for debugging
This commit is contained in:
parent
35f6c3850e
commit
a3a8fb4e84
@ -11,10 +11,15 @@ namespace Syntriax.Engine.Serialization;
|
||||
|
||||
public class InstanceConverter : IEngineTypeYamlConverter
|
||||
{
|
||||
private int depth = 0;
|
||||
private int maxDepth = 5;
|
||||
|
||||
public bool Accepts(Type type) => !type.IsPrimitive && type != typeof(string);
|
||||
|
||||
public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||
{
|
||||
if (depth > maxDepth)
|
||||
return null;
|
||||
parser.Consume<MappingStart>();
|
||||
|
||||
TypeContainer typeContainer = (TypeContainer)rootDeserializer(typeof(TypeContainer))!;
|
||||
@ -27,12 +32,16 @@ public class InstanceConverter : IEngineTypeYamlConverter
|
||||
|
||||
if (type.GetField(key, BindingFlags.Instance | BindingFlags.NonPublic) is FieldInfo fieldInfo)
|
||||
{
|
||||
depth++;
|
||||
object? fieldValue = rootDeserializer(fieldInfo.FieldType);
|
||||
depth--;
|
||||
fieldInfo.SetValue(instance, fieldValue);
|
||||
}
|
||||
else if (type.GetProperty(key) is PropertyInfo propertyInfo)
|
||||
{
|
||||
depth++;
|
||||
object? propertyValue = rootDeserializer(propertyInfo.PropertyType);
|
||||
depth--;
|
||||
propertyInfo.SetValue(instance, propertyValue);
|
||||
}
|
||||
else
|
||||
@ -56,13 +65,15 @@ public class InstanceConverter : IEngineTypeYamlConverter
|
||||
if (propertyInfo.GetCustomAttribute<IgnoreSerializationAttribute>() is not null)
|
||||
continue;
|
||||
|
||||
if ((propertyInfo.PropertyType.IsClass && propertyInfo.PropertyType != typeof(string)) || propertyInfo.PropertyType.IsAbstract)
|
||||
continue;
|
||||
|
||||
emitter.Emit(new Scalar(propertyInfo.Name));
|
||||
object? propertyValue = propertyInfo.GetValue(value);
|
||||
|
||||
EmitValue(propertyValue, propertyInfo.PropertyType, emitter, serializer);
|
||||
depth++;
|
||||
if (depth <= maxDepth)
|
||||
EmitValue(propertyValue, propertyInfo.PropertyType, emitter, serializer);
|
||||
else
|
||||
emitter.Emit(new Scalar("Skipped"));
|
||||
depth--;
|
||||
}
|
||||
|
||||
foreach (FieldInfo fieldInfo in typeData.Fields)
|
||||
@ -70,16 +81,18 @@ public class InstanceConverter : IEngineTypeYamlConverter
|
||||
if (fieldInfo.GetCustomAttribute<System.Runtime.CompilerServices.CompilerGeneratedAttribute>() is not null)
|
||||
continue;
|
||||
|
||||
if (fieldInfo.GetCustomAttribute<SerializeAttribute>() is null)
|
||||
continue;
|
||||
|
||||
if ((fieldInfo.FieldType.IsClass && fieldInfo.FieldType != typeof(string)) || fieldInfo.FieldType.IsAbstract)
|
||||
continue;
|
||||
// if (fieldInfo.GetCustomAttribute<SerializeAttribute>() is null)
|
||||
// continue;
|
||||
|
||||
emitter.Emit(new Scalar(fieldInfo.Name));
|
||||
object? fieldValue = fieldInfo.GetValue(value);
|
||||
|
||||
EmitValue(fieldValue, fieldInfo.FieldType, emitter, serializer);
|
||||
depth++;
|
||||
if (depth <= maxDepth)
|
||||
EmitValue(fieldValue, fieldInfo.FieldType, emitter, serializer);
|
||||
else
|
||||
emitter.Emit(new Scalar("Skipped"));
|
||||
depth--;
|
||||
}
|
||||
|
||||
emitter.Emit(new MappingEnd());
|
||||
|
Loading…
x
Reference in New Issue
Block a user