Skip to content

Commit 154302b

Browse files
committed
Solve primite argument
1 parent c218dc2 commit 154302b

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

src/DynamoDBGenerator.SourceGenerator/Generations/AttributeExpressionValue.cs

+19-17
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,25 @@ internal static IEnumerable<string> CreateExpressionAttributeValue(IEnumerable<D
8686
}
8787
private static CodeFactory CreateStruct(ITypeSymbol typeSymbol, Func<ITypeSymbol, ImmutableArray<DynamoDbDataMember>> fn, MarshallerOptions options)
8888
{
89-
// TODO
90-
if (options.IsConvertable(typeSymbol))
91-
{
92-
93-
}
94-
var dataMembers = fn(typeSymbol)
95-
.Select(x =>
96-
{
97-
return (
98-
IsUnknown: !options.IsConvertable(x.DataMember.Type) && x.DataMember.Type.TypeIdentifier() is UnknownType,
99-
DDB: x,
100-
ValueRef: $"_{x.DataMember.Name}ValueRef",
101-
AttributeReference: TypeName(x.DataMember.Type),
102-
AttributeInterfaceName: $"{Constants.DynamoDBGenerator.Marshaller.AttributeExpressionValueTrackerInterface}<{x.DataMember.Type.Representation().annotated}>"
103-
);
104-
})
105-
.ToArray();
89+
var dataMembers =
90+
options.IsConvertable(typeSymbol)
91+
? Array
92+
.Empty<(bool IsUnknown, DynamoDbDataMember DDB, string ValueRef, string AttributeReference, string
93+
AttributeInterfaceName)>()
94+
: fn(typeSymbol)
95+
.Select(x =>
96+
{
97+
return (
98+
IsUnknown: !options.IsConvertable(x.DataMember.Type) &&
99+
x.DataMember.Type.TypeIdentifier() is UnknownType,
100+
DDB: x,
101+
ValueRef: $"_{x.DataMember.Name}ValueRef",
102+
AttributeReference: TypeName(x.DataMember.Type),
103+
AttributeInterfaceName:
104+
$"{Constants.DynamoDBGenerator.Marshaller.AttributeExpressionValueTrackerInterface}<{x.DataMember.Type.Representation().annotated}>"
105+
);
106+
})
107+
.ToArray();
106108

107109
var structName = TypeName(typeSymbol);
108110
var interfaceName = $"{Constants.DynamoDBGenerator.Marshaller.AttributeExpressionValueTrackerInterface}<{typeSymbol.Representation().annotated}>";
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
using Amazon.DynamoDBv2.Model;
12
using DynamoDBGenerator.Attributes;
23

34
namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests;
45

56
[DynamoDBMarshaller(typeof((Guid, Guid)), PropertyName = "PrimitiveArgument", ArgumentType = typeof(string))]
67
public partial class PrimitiveArgumentTests
78
{
8-
99
[Fact]
10-
public void Test()
10+
public void ExpressionValueTracker_String_ShouldBeExpandedCorrectly()
1111
{
12-
PrimitiveArgument.
12+
IAttributeExpressionValueTracker<string> valueTracker = PrimitiveArgument.AttributeExpressionValueTracker();
13+
valueTracker.ToString().Should().Be(":p1");
14+
15+
valueTracker.AccessedValues("hello").Should().BeEquivalentTo(new Dictionary<string, AttributeValue>
16+
{
17+
{ ":p1", new AttributeValue { S = "hello" } }
18+
});
1319
}
1420
}

0 commit comments

Comments
 (0)