Fixed primitive fields not being serialised

This commit is contained in:
Kah Wei 2022-10-20 10:10:43 +08:00
parent cfed342f9c
commit 4bc91283c8
2 changed files with 45 additions and 44 deletions

View File

@ -73,7 +73,7 @@ namespace SHADE
// Create YAML object
YAML::Node scriptNode;
scriptNode.SetStyle(YAML::EmitterStyle::Block);
scriptNode[SCRIPT_TYPE_YAMLTAG] = Convert::ToNative(object->GetType()->FullName);
scriptNode[SCRIPT_TYPE_YAMLTAG.data()] = Convert::ToNative(object->GetType()->FullName);
// Get all fields
System::Collections::Generic::IEnumerable<FieldInfo^>^ fields = GetInstanceFields(object);
@ -129,7 +129,7 @@ namespace SHADE
YAML::Node fieldNode;
// Retrieve string for the YAML
if (fieldInsertYaml<System::Int16> (fieldInfo, object, fieldNode) ||
const bool PRIMITIVE_SERIALIZED = fieldInsertYaml<System::Int16>(fieldInfo, object, fieldNode) ||
fieldInsertYaml<System::Int32>(fieldInfo, object, fieldNode) ||
fieldInsertYaml<System::Int64>(fieldInfo, object, fieldNode) ||
fieldInsertYaml<System::UInt16>(fieldInfo, object, fieldNode) ||
@ -138,11 +138,12 @@ namespace SHADE
fieldInsertYaml<System::Byte>(fieldInfo, object, fieldNode) ||
fieldInsertYaml<bool>(fieldInfo, object, fieldNode) ||
fieldInsertYaml<float>(fieldInfo, object, fieldNode) ||
fieldInsertYaml<double> (fieldInfo, object, fieldNode))
fieldInsertYaml<double>(fieldInfo, object, fieldNode);
// Serialization of more complex types
if (!PRIMITIVE_SERIALIZED)
{
return;
}
else if (fieldInfo->FieldType->IsSubclassOf(System::Enum::typeid))
if (fieldInfo->FieldType->IsSubclassOf(System::Enum::typeid))
{
fieldNode = std::to_string(safe_cast<int>(fieldInfo->GetValue(object)));
}
@ -175,6 +176,7 @@ namespace SHADE
));
return;
}
}
// Store the field into YAML
yamlNode[Convert::ToNative(fieldInfo->Name)] = fieldNode;

View File

@ -58,8 +58,7 @@ namespace SHADE
/// deserialised data into the specified object if there are matching fields.
/// </summary>
/// <param name="yamlNode">
/// The JSON string that contains the data to copy into this PlushieScript
/// object.
/// The JSON string that contains the data to copy into this Script object.
/// </param>
/// <param name="object">The object to copy deserialised data into.</param>
static void Deserialise(System::Object^ object, YAML::Node& yamlNode);