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 25 additions and 0 deletions
Showing only changes of commit 17662abef1 - Show all commits

View File

@ -142,6 +142,31 @@ namespace SHADE
bool SerialisationUtilities::fieldAssignYaml(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Node& node) bool SerialisationUtilities::fieldAssignYaml(System::Reflection::FieldInfo^ fieldInfo, Object^ object, YAML::Node& node)
{ {
System::Object^ valueObj = fieldInfo->GetValue(object); System::Object^ valueObj = fieldInfo->GetValue(object);
if (valueObj == nullptr)
{
if constexpr (std::is_same_v<FieldType, System::Enum>)
{
if (fieldInfo->FieldType->IsSubclassOf(System::Enum::typeid))
{
valueObj = 0;
}
}
else
{
if (fieldInfo->FieldType == FieldType::typeid)
{
if constexpr (std::is_same_v<FieldType, System::String>)
{
valueObj = "";
}
else
{
valueObj = FieldType();
}
}
}
}
if (varAssignYamlInternal<FieldType>(valueObj, node)) if (varAssignYamlInternal<FieldType>(valueObj, node))
{ {
fieldInfo->SetValue(object, valueObj); fieldInfo->SetValue(object, valueObj);