fix: yaml serialization issues caused by class converter treating primitives as classes
This commit is contained in:
@@ -20,8 +20,8 @@ public class SerializedClassConverter : EngineTypeYamlSerializerBase<SerializedC
|
|||||||
ProgressionTracker.Set(isTrackingController ? .1f : ProgressionTracker.Progression, $"Reading class");
|
ProgressionTracker.Set(isTrackingController ? .1f : ProgressionTracker.Progression, $"Reading class");
|
||||||
|
|
||||||
SerializedClass serializedClass = new();
|
SerializedClass serializedClass = new();
|
||||||
Dictionary<string, TypeContainer> publicDictionary = [];
|
Dictionary<string, object> publicDictionary = [];
|
||||||
Dictionary<string, TypeContainer> privateDictionary = [];
|
Dictionary<string, object> privateDictionary = [];
|
||||||
|
|
||||||
parser.Consume<MappingStart>();
|
parser.Consume<MappingStart>();
|
||||||
|
|
||||||
@@ -32,16 +32,24 @@ public class SerializedClassConverter : EngineTypeYamlSerializerBase<SerializedC
|
|||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case nameof(SerializedClass.Type): serializedClass.Type = parser.Consume<Scalar>().Value; break;
|
case nameof(SerializedClass.Type): serializedClass.Type = parser.Consume<Scalar>().Value; break;
|
||||||
case nameof(SerializedClass.Public): publicDictionary = (Dictionary<string, TypeContainer>)rootDeserializer(typeof(Dictionary<string, TypeContainer>))!; break;
|
case nameof(SerializedClass.Public): publicDictionary = (Dictionary<string, object>)rootDeserializer(typeof(Dictionary<string, object>))!; break;
|
||||||
case nameof(SerializedClass.Private): privateDictionary = (Dictionary<string, TypeContainer>)rootDeserializer(typeof(Dictionary<string, TypeContainer>))!; break;
|
case nameof(SerializedClass.Private): privateDictionary = (Dictionary<string, object>)rootDeserializer(typeof(Dictionary<string, object>))!; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ((string key, TypeContainer typeContainer) in publicDictionary)
|
Type classType = TypeFactory.GetType(serializedClass.Type);
|
||||||
serializedClass.Public.Add(key, Serializer.InternalDeserialize(typeContainer.Value!.ToString()!, TypeFactory.GetType(typeContainer.Type)));
|
|
||||||
|
|
||||||
foreach ((string key, TypeContainer typeContainer) in privateDictionary)
|
foreach ((string key, object @object) in publicDictionary)
|
||||||
serializedClass.Private.Add(key, Serializer.InternalDeserialize(typeContainer.Value!.ToString()!, TypeFactory.GetType(typeContainer.Type)));
|
if (@object is TypeContainer typeContainer)
|
||||||
|
serializedClass.Public.Add(key, Serializer.InternalDeserialize(typeContainer.Value!.ToString()!, TypeFactory.GetType(typeContainer.Type)));
|
||||||
|
else
|
||||||
|
serializedClass.Public.Add(key, Serializer.InternalDeserialize(@object.ToString()!, (classType.GetProperty(key, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)?.PropertyType ?? classType.GetField(key, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)?.FieldType)!));
|
||||||
|
|
||||||
|
foreach ((string key, object @object) in privateDictionary)
|
||||||
|
if (@object is TypeContainer typeContainer)
|
||||||
|
serializedClass.Private.Add(key, Serializer.InternalDeserialize(typeContainer.Value!.ToString()!, TypeFactory.GetType(typeContainer.Type)));
|
||||||
|
else
|
||||||
|
serializedClass.Private.Add(key, Serializer.InternalDeserialize(@object.ToString()!, (classType.GetProperty(key, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Default)?.PropertyType ?? classType.GetField(key, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Default)?.FieldType)!));
|
||||||
|
|
||||||
ProgressionTracker.Set(isTrackingController ? 1f : ProgressionTracker.Progression, $"Read {serializedClass.Type}");
|
ProgressionTracker.Set(isTrackingController ? 1f : ProgressionTracker.Progression, $"Read {serializedClass.Type}");
|
||||||
return serializedClass;
|
return serializedClass;
|
||||||
@@ -54,14 +62,20 @@ public class SerializedClassConverter : EngineTypeYamlSerializerBase<SerializedC
|
|||||||
bool isTrackingController = ProgressionTracker.Progression.ApproximatelyEquals(0f);
|
bool isTrackingController = ProgressionTracker.Progression.ApproximatelyEquals(0f);
|
||||||
ProgressionTracker.Set(isTrackingController ? .25f : ProgressionTracker.Progression, $"Serializing {serializedClass.Type}");
|
ProgressionTracker.Set(isTrackingController ? .25f : ProgressionTracker.Progression, $"Serializing {serializedClass.Type}");
|
||||||
|
|
||||||
Dictionary<string, TypeContainer> publics = [];
|
Dictionary<string, object> publics = [];
|
||||||
Dictionary<string, TypeContainer> privates = [];
|
Dictionary<string, object> privates = [];
|
||||||
|
|
||||||
foreach ((string key, object? @object) in serializedClass.Public.Where(v => !v.GetType().HasAttribute<IgnoreSerializationAttribute>()))
|
foreach ((string key, object? @object) in serializedClass.Public.Where(v => !v.GetType().HasAttribute<IgnoreSerializationAttribute>()))
|
||||||
publics.Add(key, new TypeContainer(@object));
|
if (@object?.GetType().IsClass == false)
|
||||||
|
publics.Add(key, @object!);
|
||||||
|
else
|
||||||
|
publics.Add(key, new TypeContainer(@object));
|
||||||
|
|
||||||
foreach ((string key, object? @object) in serializedClass.Private.Where(v => !v.GetType().HasAttribute<IgnoreSerializationAttribute>()))
|
foreach ((string key, object? @object) in serializedClass.Private.Where(v => !v.GetType().HasAttribute<IgnoreSerializationAttribute>()))
|
||||||
privates.Add(key, new TypeContainer(@object));
|
if (@object?.GetType().IsClass == false)
|
||||||
|
privates.Add(key, @object!);
|
||||||
|
else
|
||||||
|
privates.Add(key, new TypeContainer(@object));
|
||||||
|
|
||||||
emitter.Emit(new MappingStart());
|
emitter.Emit(new MappingStart());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user