fix(core): Fixes various issues with codegen (#646)

- [X] Fixes bad `ReadEnum` by size
- [X] Fixes array, list, and set not handling null values properly.
  - It will be up to the user (for now) to null out empty lists using `[AfterDeserialization]`. Convenience may be added later.
- [X] Fixes errors with `dotnet clean` and non-empty generation folder
- [X] Fixes bad field indexes on `Account.cs` causing `tags` to not be serialized/deserialized.
  - This was caused by a duplicate entry. Don't have protection against this _yet_.
This commit is contained in:
Kamron Batman 2021-06-06 17:03:05 -07:00 committed by GitHub
parent 75db56edc4
commit eb4e3ac070
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 21 deletions

View file

@ -114,10 +114,15 @@ namespace SerializableMigration
Array.Copy(ruleArguments, 2, listElementRuleArguments, 0, ruleArguments.Length - 2);
var propertyName = property.Name;
var propertyEntry = $"{char.ToLower(propertyName[0])}{propertyName.Substring(1, propertyName.Length - 1)}Entry";
source.AppendLine($"{indent}writer.Write({propertyName}.Count);");
source.AppendLine($"{indent}foreach (var {propertyEntry} in {propertyName})");
var propertyVarPrefix = $"{char.ToLower(propertyName[0])}{propertyName.Substring(1, propertyName.Length - 1)}";
var propertyEntry = $"{propertyVarPrefix}Entry";
var propertyCount = $"{propertyVarPrefix}Count";
source.AppendLine($"{indent}var {propertyCount} = {property.Name}?.Count ?? 0;");
source.AppendLine($"{indent}writer.Write({propertyCount});");
source.AppendLine($"{indent}if ({propertyCount} > 0)");
source.AppendLine($"{indent}{{");
source.AppendLine($"{indent} foreach (var {propertyEntry} in {property.Name}!)");
source.AppendLine($"{indent} {{");
var serializableListElement = new SerializableProperty
{
@ -127,8 +132,9 @@ namespace SerializableMigration
RuleArguments = listElementRuleArguments
};
listElementRule.GenerateSerializationMethod(source, $"{indent} ", serializableListElement);
listElementRule.GenerateSerializationMethod(source, $"{indent} ", serializableListElement);
source.AppendLine($"{indent} }}");
source.AppendLine($"{indent}}}");
}
}