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:
parent
75db56edc4
commit
eb4e3ac070
8 changed files with 47 additions and 21 deletions
|
|
@ -101,14 +101,18 @@ namespace SerializableMigration
|
|||
var arrayElementRuleArguments = new string[ruleArguments.Length - 2];
|
||||
Array.Copy(ruleArguments, 2, arrayElementRuleArguments, 0, ruleArguments.Length - 2);
|
||||
|
||||
var propertyIndex = $"{property.Name}Index";
|
||||
source.AppendLine($"{indent}writer.Write({property.Name}.Length);");
|
||||
source.AppendLine($"{indent}for (var {propertyIndex} = 0; {propertyIndex} < {property.Name}.Length; {propertyIndex}++)");
|
||||
var propertyName = property.Name;
|
||||
var propertyVarPrefix = $"{char.ToLower(propertyName[0])}{propertyName.Substring(1, propertyName.Length - 1)}";
|
||||
var propertyIndex = $"{propertyVarPrefix}Index";
|
||||
var propertyLength = $"{propertyVarPrefix}Length";
|
||||
source.AppendLine($"{indent}var {propertyLength} = {property.Name}?.Length ?? 0;");
|
||||
source.AppendLine($"{indent}writer.Write({propertyLength});");
|
||||
source.AppendLine($"{indent}for (var {propertyIndex} = 0; {propertyIndex} < {propertyLength}; {propertyIndex}++)");
|
||||
source.AppendLine($"{indent}{{");
|
||||
|
||||
var serializableArrayElement = new SerializableProperty
|
||||
{
|
||||
Name = $"{property.Name}[{propertyIndex}]",
|
||||
Name = $"{property.Name}![{propertyIndex}]",
|
||||
Type = ruleArguments[0],
|
||||
Rule = arrayElementRule.RuleName,
|
||||
RuleArguments = arrayElementRuleArguments
|
||||
|
|
|
|||
|
|
@ -116,9 +116,13 @@ namespace SerializableMigration
|
|||
var propertyName = property.Name;
|
||||
var propertyVarPrefix = $"{char.ToLower(propertyName[0])}{propertyName.Substring(1, propertyName.Length - 1)}";
|
||||
var propertyEntry = $"{propertyVarPrefix}Entry";
|
||||
source.AppendLine($"{indent}writer.Write({property.Name}.Count);");
|
||||
source.AppendLine($"{indent}foreach (var {propertyEntry} in {property.Name});");
|
||||
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 serializableSetElement = new SerializableProperty
|
||||
{
|
||||
|
|
@ -128,8 +132,9 @@ namespace SerializableMigration
|
|||
RuleArguments = setElementRuleArguments
|
||||
};
|
||||
|
||||
setElementRule.GenerateSerializationMethod(source, $"{indent} ", serializableSetElement);
|
||||
setElementRule.GenerateSerializationMethod(source, $"{indent} ", serializableSetElement);
|
||||
|
||||
source.AppendLine($"{indent} }}");
|
||||
source.AppendLine($"{indent}}}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}}}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue