Fixed edge cases for serialization and deserialization of scripts #218

Merged
Pycorax merged 3 commits from SP3-6-c-scripting into main 2022-11-17 17:17:13 +08:00
1 changed files with 33 additions and 13 deletions
Showing only changes of commit 042bff5c1a - Show all commits

View File

@ -45,12 +45,22 @@ namespace SHADE
System::Collections::Generic::IEnumerable<FieldInfo^>^ fields = ReflectionUtilities::GetInstanceFields(object); System::Collections::Generic::IEnumerable<FieldInfo^>^ fields = ReflectionUtilities::GetInstanceFields(object);
for each (FieldInfo^ field in fields) for each (FieldInfo^ field in fields)
{ {
// Ignore private and non-SerialiseField try
if (!ReflectionUtilities::FieldIsSerialisable(field)) {
continue; // Ignore private and non-SerialiseField
if (!ReflectionUtilities::FieldIsSerialisable(field))
continue;
// Serialise // Serialise
writeFieldIntoYaml(field, object, scriptNode); writeFieldIntoYaml(field, object, scriptNode);
}
catch (System::Exception^ e)
{
Debug::LogError
(
System::String::Format("[SerialisationUtilities] Failed to serialise field ({0}): {1}", field->Name, e->ToString())
);
}
} }
scriptListNode.push_back(scriptNode); scriptListNode.push_back(scriptNode);
@ -74,15 +84,25 @@ namespace SHADE
System::Collections::Generic::IEnumerable<FieldInfo^>^ fields = ReflectionUtilities::GetInstanceFields(object); System::Collections::Generic::IEnumerable<FieldInfo^>^ fields = ReflectionUtilities::GetInstanceFields(object);
for each (FieldInfo^ field in fields) for each (FieldInfo^ field in fields)
{ {
// Ignore private and non-SerialiseField try
if (!ReflectionUtilities::FieldIsSerialisable(field))
continue;
// Deserialise
const std::string FIELD_NAME = Convert::ToNative(field->Name);
if (yamlNode[FIELD_NAME])
{ {
writeYamlIntoField(field, object, yamlNode[FIELD_NAME]); // Ignore private and non-SerialiseField
if (!ReflectionUtilities::FieldIsSerialisable(field))
continue;
// Deserialise
const std::string FIELD_NAME = Convert::ToNative(field->Name);
if (yamlNode[FIELD_NAME])
{
writeYamlIntoField(field, object, yamlNode[FIELD_NAME]);
}
}
catch (System::Exception^ e)
{
Debug::LogError
(
System::String::Format("[SerialisationUtilities] Failed to deserialise field ({0}): {1}", field->Name, e->ToString())
);
} }
} }
} }