Compare commits

..

No commits in common. "dev" and "main" have entirely different histories.
dev ... main

View File

@ -858,8 +858,7 @@ public class GrpcGenerator : IIncrementalGenerator
var constructorType = prop.FullyQualifiedType.TrimEnd('?'); var constructorType = prop.FullyQualifiedType.TrimEnd('?');
return $"{indent}{prop.Name} = new {constructorType}({source}?.Items?.Select(x => System.Guid.Parse(x)).ToArray() ?? System.Array.Empty<System.Guid>()),"; return $"{indent}{prop.Name} = new {constructorType}({source}?.Items?.Select(x => System.Guid.Parse(x)).ToArray() ?? System.Array.Empty<System.Guid>()),";
} }
// proto repeated fields are never null — drop ?. to avoid CS8601 on assignment to non-nullable target return $"{indent}{prop.Name} = {source}?.Select(x => System.Guid.Parse(x)).ToList(),";
return $"{indent}{prop.Name} = {source}.Select(x => System.Guid.Parse(x)).ToList(),";
} }
else if (prop.IsValueTypeCollection) else if (prop.IsValueTypeCollection)
{ {
@ -870,8 +869,7 @@ public class GrpcGenerator : IIncrementalGenerator
else else
{ {
// Primitive list: just ToList() // Primitive list: just ToList()
// proto repeated fields are never null — drop ?. to avoid CS8601 on assignment to non-nullable target return $"{indent}{prop.Name} = {source}?.ToList(),";
return $"{indent}{prop.Name} = {source}.ToList(),";
} }
} }
@ -886,11 +884,11 @@ public class GrpcGenerator : IIncrementalGenerator
{ {
if (prop.IsNullable) if (prop.IsNullable)
{ {
return $"{indent}{prop.Name} = string.IsNullOrEmpty({source}) ? null : decimal.Parse({source}, System.Globalization.CultureInfo.InvariantCulture),"; return $"{indent}{prop.Name} = string.IsNullOrEmpty({source}) ? null : decimal.Parse({source}),";
} }
else else
{ {
return $"{indent}{prop.Name} = decimal.Parse({source}, System.Globalization.CultureInfo.InvariantCulture),"; return $"{indent}{prop.Name} = decimal.Parse({source}),";
} }
} }
@ -971,9 +969,7 @@ public class GrpcGenerator : IIncrementalGenerator
var sb = new StringBuilder(); var sb = new StringBuilder();
// For value type collections, the proto message has an Items field containing the repeated elements // For value type collections, the proto message has an Items field containing the repeated elements
var itemsSource = prop.IsValueTypeCollection ? $"{source}?.Items" : source; var itemsSource = prop.IsValueTypeCollection ? $"{source}?.Items" : source;
// Value-type wrapper messages can be null (?.Items needs ?.). Plain proto repeated is never null. sb.AppendLine($"{indent}{prop.Name} = {itemsSource}?.Select(x => new {prop.ElementType}");
var selectAccess = prop.IsValueTypeCollection ? "?." : ".";
sb.AppendLine($"{indent}{prop.Name} = {itemsSource}{selectAccess}Select(x => new {prop.ElementType}");
sb.AppendLine($"{indent}{{"); sb.AppendLine($"{indent}{{");
foreach (var nestedProp in prop.ElementNestedProperties!) foreach (var nestedProp in prop.ElementNestedProperties!)
@ -1035,11 +1031,11 @@ public class GrpcGenerator : IIncrementalGenerator
{ {
if (prop.IsNullable) if (prop.IsNullable)
{ {
return $"{indent}{prop.Name} = string.IsNullOrEmpty({source}) ? null : decimal.Parse({source}, System.Globalization.CultureInfo.InvariantCulture),"; return $"{indent}{prop.Name} = string.IsNullOrEmpty({source}) ? null : decimal.Parse({source}),";
} }
else else
{ {
return $"{indent}{prop.Name} = decimal.Parse({source}, System.Globalization.CultureInfo.InvariantCulture),"; return $"{indent}{prop.Name} = decimal.Parse({source}),";
} }
} }
@ -1082,8 +1078,7 @@ public class GrpcGenerator : IIncrementalGenerator
var constructorType = prop.FullyQualifiedType.TrimEnd('?'); var constructorType = prop.FullyQualifiedType.TrimEnd('?');
return $"{indent}{prop.Name} = new {constructorType}({source}?.ToArray() ?? System.Array.Empty<{prop.ElementType ?? "object"}>()),"; return $"{indent}{prop.Name} = new {constructorType}({source}?.ToArray() ?? System.Array.Empty<{prop.ElementType ?? "object"}>()),";
} }
// proto repeated fields are never null — drop ?. to avoid CS8601 return $"{indent}{prop.Name} = {source}?.ToList(),";
return $"{indent}{prop.Name} = {source}.ToList(),";
} }
// Handle complex types // Handle complex types