Fixed bug where certain null objects in deserialization was not handled

This commit is contained in:
Kah Wei 2022-11-17 15:42:40 +08:00
parent 098c621316
commit 17662abef1
1 changed files with 25 additions and 0 deletions

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);