Skip to content

Commit d89deeb

Browse files
committed
Fix special syntax
1 parent 29a4d51 commit d89deeb

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

src/DynamoDBGenerator.SourceGenerator/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public static class Marshaller
8181
public static class AttributeValueUtilityFactory
8282
{
8383
private const string ClassName = "MarshallHelper";
84+
public const string ToAttributeValue = $"{ClassName}.ToAttributeValue";
8485
public const string Null = $"{ClassName}.Null";
8586
public const string ToList = $"{ClassName}.ToList";
8687
public const string ToArray = $"{ClassName}.ToArray";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ internal static string InvokeMarshallerMethod(ITypeSymbol typeSymbol, string par
216216

217217
if (typeSymbol.TypeIdentifier() is UnknownType)
218218
return typeSymbol.IsNullable()
219-
? $"{invocation} switch {{ {{ }} x => new {Constants.AWSSDK_DynamoDBv2.AttributeValue} {{ M = x }}, null => null }}"
219+
? $"{AttributeValueUtilityFactory.ToAttributeValue}({invocation})"
220220
: $"new {Constants.AWSSDK_DynamoDBv2.AttributeValue} {{ M = {invocation} }}";
221221

222222
return invocation;

src/DynamoDBGenerator/Internal/MarshallHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public static class MarshallHelper
1717
#pragma warning disable CS1591
1818
public static AttributeValue Null { get; } = new() { NULL = true };
1919

20+
public static AttributeValue? ToAttributeValue(Dictionary<string, AttributeValue>? dict) => dict is null
21+
? null
22+
: new AttributeValue { M = dict };
2023

2124
public static AttributeValue FromDictionary<T, TArgument>(
2225
IEnumerable<KeyValuePair<string, T>> dictionary,

0 commit comments

Comments
 (0)