Fixed primitive fields not being serialised
This commit is contained in:
parent
cfed342f9c
commit
4bc91283c8
|
@ -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,20 +129,21 @@ namespace SHADE
|
|||
YAML::Node fieldNode;
|
||||
|
||||
// Retrieve string for the YAML
|
||||
if (fieldInsertYaml<System::Int16> (fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<System::Int32> (fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<System::Int64> (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) ||
|
||||
fieldInsertYaml<System::UInt32>(fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<System::UInt64>(fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<System::Byte> (fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<bool> (fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<float> (fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<double> (fieldInfo, object, fieldNode))
|
||||
fieldInsertYaml<System::Byte>(fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<bool>(fieldInfo, object, fieldNode) ||
|
||||
fieldInsertYaml<float>(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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue