diff --git a/Svrnty.CQRS.Grpc.Generators/GrpcGenerator.cs b/Svrnty.CQRS.Grpc.Generators/GrpcGenerator.cs index d1fd41e..49731eb 100644 --- a/Svrnty.CQRS.Grpc.Generators/GrpcGenerator.cs +++ b/Svrnty.CQRS.Grpc.Generators/GrpcGenerator.cs @@ -858,7 +858,8 @@ public class GrpcGenerator : IIncrementalGenerator var constructorType = prop.FullyQualifiedType.TrimEnd('?'); return $"{indent}{prop.Name} = new {constructorType}({source}?.Items?.Select(x => System.Guid.Parse(x)).ToArray() ?? System.Array.Empty()),"; } - return $"{indent}{prop.Name} = {source}?.Select(x => System.Guid.Parse(x)).ToList(),"; + // 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(),"; } else if (prop.IsValueTypeCollection) { @@ -869,7 +870,8 @@ public class GrpcGenerator : IIncrementalGenerator else { // Primitive list: just ToList() - return $"{indent}{prop.Name} = {source}?.ToList(),"; + // proto repeated fields are never null — drop ?. to avoid CS8601 on assignment to non-nullable target + return $"{indent}{prop.Name} = {source}.ToList(),"; } } @@ -969,7 +971,9 @@ public class GrpcGenerator : IIncrementalGenerator var sb = new StringBuilder(); // For value type collections, the proto message has an Items field containing the repeated elements var itemsSource = prop.IsValueTypeCollection ? $"{source}?.Items" : source; - sb.AppendLine($"{indent}{prop.Name} = {itemsSource}?.Select(x => new {prop.ElementType}"); + // Value-type wrapper messages can be null (?.Items needs ?.). Plain proto repeated is never null. + var selectAccess = prop.IsValueTypeCollection ? "?." : "."; + sb.AppendLine($"{indent}{prop.Name} = {itemsSource}{selectAccess}Select(x => new {prop.ElementType}"); sb.AppendLine($"{indent}{{"); foreach (var nestedProp in prop.ElementNestedProperties!) @@ -1078,7 +1082,8 @@ public class GrpcGenerator : IIncrementalGenerator var constructorType = prop.FullyQualifiedType.TrimEnd('?'); return $"{indent}{prop.Name} = new {constructorType}({source}?.ToArray() ?? System.Array.Empty<{prop.ElementType ?? "object"}>()),"; } - return $"{indent}{prop.Name} = {source}?.ToList(),"; + // proto repeated fields are never null — drop ?. to avoid CS8601 + return $"{indent}{prop.Name} = {source}.ToList(),"; } // Handle complex types