Skip to content

Commit 6d6f7e0

Browse files
committed
Create variables
1 parent 421abfb commit 6d6f7e0

File tree

1 file changed

+5
-3
lines changed
  • src/DynamoDBGenerator.SourceGenerator/Generations/Marshalling

1 file changed

+5
-3
lines changed

src/DynamoDBGenerator.SourceGenerator/Generations/Marshalling/Marshaller.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ private static CodeFactory CreateDictionaryMethod(ITypeSymbol typeSymbol, Func<I
2525
var isNullable = x.DataMember.Type.IsNullable();
2626

2727
var marshallerInvocation = InvokeMarshallerMethod(x.DataMember.Type, accessPattern, $"\"{x.DataMember.Name}\"", options);
28+
2829
var assignment = isNullable
29-
? $"if ({marshallerInvocation} is {{ }} {x.DataMember.Name})"
30-
.CreateScope($"{DictionaryReference}[\"{x.AttributeName}\"] = {x.DataMember.Name};")
31-
: new[] { $"{DictionaryReference}[\"{x.AttributeName}\"] = {marshallerInvocation};"};
30+
? $"if ({x.DataMember.NameAsCamelCase} is not null)"
31+
.CreateScope($"{DictionaryReference}[\"{x.AttributeName}\"] = {x.DataMember.NameAsCamelCase};")
32+
.Prepend($"var {x.DataMember.NameAsCamelCase} = {marshallerInvocation};")
33+
: new[] { $"{DictionaryReference}[\"{x.AttributeName}\"] = {marshallerInvocation};" };
3234

3335
return (
3436
dictionaryAssignment: assignment,

0 commit comments

Comments
 (0)