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

@ -44,6 +44,8 @@ namespace SHADE
// Get all fields // Get all fields
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)
{
try
{ {
// Ignore private and non-SerialiseField // Ignore private and non-SerialiseField
if (!ReflectionUtilities::FieldIsSerialisable(field)) if (!ReflectionUtilities::FieldIsSerialisable(field))
@ -52,6 +54,14 @@ namespace SHADE
// 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);
} }
@ -73,6 +83,8 @@ namespace SHADE
// Get all fields // Get all fields
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)
{
try
{ {
// Ignore private and non-SerialiseField // Ignore private and non-SerialiseField
if (!ReflectionUtilities::FieldIsSerialisable(field)) if (!ReflectionUtilities::FieldIsSerialisable(field))
@ -85,6 +97,14 @@ namespace SHADE
writeYamlIntoField(field, object, 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())
);
}
}
} }
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Serialization Helper Functions */ /* Serialization Helper Functions */