Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a05ebad7fc | ||
|
|
ee3ad866d9 |
@ -858,7 +858,8 @@ 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>()),";
|
||||||
}
|
}
|
||||||
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)
|
else if (prop.IsValueTypeCollection)
|
||||||
{
|
{
|
||||||
@ -869,7 +870,8 @@ public class GrpcGenerator : IIncrementalGenerator
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Primitive list: just ToList()
|
// 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(),";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -884,11 +886,11 @@ public class GrpcGenerator : IIncrementalGenerator
|
|||||||
{
|
{
|
||||||
if (prop.IsNullable)
|
if (prop.IsNullable)
|
||||||
{
|
{
|
||||||
return $"{indent}{prop.Name} = string.IsNullOrEmpty({source}) ? null : decimal.Parse({source}),";
|
return $"{indent}{prop.Name} = string.IsNullOrEmpty({source}) ? null : decimal.Parse({source}, System.Globalization.CultureInfo.InvariantCulture),";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return $"{indent}{prop.Name} = decimal.Parse({source}),";
|
return $"{indent}{prop.Name} = decimal.Parse({source}, System.Globalization.CultureInfo.InvariantCulture),";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -969,7 +971,9 @@ 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;
|
||||||
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}{{");
|
sb.AppendLine($"{indent}{{");
|
||||||
|
|
||||||
foreach (var nestedProp in prop.ElementNestedProperties!)
|
foreach (var nestedProp in prop.ElementNestedProperties!)
|
||||||
@ -1031,11 +1035,11 @@ public class GrpcGenerator : IIncrementalGenerator
|
|||||||
{
|
{
|
||||||
if (prop.IsNullable)
|
if (prop.IsNullable)
|
||||||
{
|
{
|
||||||
return $"{indent}{prop.Name} = string.IsNullOrEmpty({source}) ? null : decimal.Parse({source}),";
|
return $"{indent}{prop.Name} = string.IsNullOrEmpty({source}) ? null : decimal.Parse({source}, System.Globalization.CultureInfo.InvariantCulture),";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return $"{indent}{prop.Name} = decimal.Parse({source}),";
|
return $"{indent}{prop.Name} = decimal.Parse({source}, System.Globalization.CultureInfo.InvariantCulture),";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1078,7 +1082,8 @@ 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"}>()),";
|
||||||
}
|
}
|
||||||
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
|
// Handle complex types
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user