Fix automatic properties serialization bug

This commit is contained in:
Wojtek Figat
2021-10-07 09:29:50 +02:00
parent 397edf18b9
commit cc29e97fa3
2 changed files with 20 additions and 2 deletions

View File

@@ -1323,8 +1323,21 @@ namespace Flax.Build.Bindings
if (GenerateCppAutoSerializationSkip(buildData, typeInfo, propertyInfo, propertyInfo.Type))
continue;
var typeHint = GenerateCppAutoSerializationDefineType(buildData, contents, moduleInfo, typeInfo, propertyInfo.Type, propertyInfo);
contents.Append($" SERIALIZE{typeHint}_MEMBER({propertyInfo.Name}, {propertyInfo.Getter.Name}());").AppendLine();
contents.Append(" {");
contents.Append(" const auto");
if (propertyInfo.Getter.ReturnType.IsConstRef)
contents.Append('&');
contents.Append($" value = {propertyInfo.Getter.Name}();");
contents.Append(" if (other) { const auto");
if (propertyInfo.Getter.ReturnType.IsConstRef)
contents.Append('&');
contents.Append($" otherValue = other->{propertyInfo.Getter.Name}();");
contents.Append(" if (Serialization::ShouldSerialize(value, &otherValue)) { ");
contents.Append($"stream.JKEY(\"{propertyInfo.Name}\"); Serialization::Serialize(stream, value, &otherValue);");
contents.Append(" } } else if (Serialization::ShouldSerialize(value, nullptr)) { ");
contents.Append($"stream.JKEY(\"{propertyInfo.Name}\"); Serialization::Serialize(stream, value, nullptr);");
contents.Append(" }");
contents.Append('}').AppendLine();
CppAutoSerializeProperties.Add(propertyInfo);
}
}

View File

@@ -28,6 +28,11 @@ namespace Flax.Build.Bindings
/// </summary>
public bool IsVoid => Type == "void" && !IsPtr;
/// <summary>
/// Gets a value indicating whether this type is constant reference to a value.
/// </summary>
public bool IsConstRef => IsRef && IsConst;
/// <summary>
/// Gets a value indicating whether this type is POD (plain old data).
/// </summary>