1
- using System . Collections ;
2
- using System . Collections . Immutable ;
3
1
using DynamoDBGenerator . SourceGenerator . Extensions ;
4
2
using DynamoDBGenerator . SourceGenerator . Types ;
5
3
using Microsoft . CodeAnalysis ;
@@ -13,7 +11,7 @@ public static class UnMarshaller
13
11
private const string DataMember = "dataMember" ;
14
12
private const string Dict = "dict" ;
15
13
private static readonly Func < ITypeSymbol , string > GetDeserializationMethodName = TypeExtensions . SuffixedTypeSymbolNameFactory ( "_U" , SymbolEqualityComparer . IncludeNullability ) ;
16
- private const string UnMarshallerClass = $ "_{ Constants . DynamoDBGenerator . Marshaller . UnmarshalMethodName } _";
14
+ private const string UnMarshallerClass = $ "_{ Marshaller . UnmarshalMethodName } _";
17
15
private const string Value = "attributeValue" ;
18
16
private static IEnumerable < ( bool useParentheses , IEnumerable < string > assignments ) > Assignments ( ITypeSymbol type , ( DynamoDbDataMember DDB , string MethodCall , string Name ) [ ] assignments )
19
17
{
@@ -66,7 +64,7 @@ private static CodeFactory CreateCode(ITypeSymbol type, Func<ITypeSymbol, Dynamo
66
64
. Prepend ( type . IsTupleType ? "return" : $ "return new { typeName . annotated . TrimEnd ( '?' ) } ")
67
65
) ;
68
66
69
- var method = $ "public static { typeName . annotated } { GetDeserializationMethodName ( type ) } (Dictionary<string, AttributeValue>? { Dict } , { MarshallerOptions . Name } { MarshallerOptions . ParamReference } , string? { DataMember } = null)". CreateScope ( blockBody ) ;
67
+ var method = $ "public static { typeName . annotated } { GetDeserializationMethodName ( type ) } (Dictionary<string, AttributeValue>? { Dict } , { options . FullName } { MarshallerOptions . ParamReference } , string? { DataMember } = null)". CreateScope ( blockBody ) ;
70
68
71
69
return new CodeFactory ( method , assignments . Select ( x => x . DDB . DataMember . Type ) ) ;
72
70
@@ -78,18 +76,18 @@ private static CodeFactory CreateMethod(ITypeSymbol type, Func<ITypeSymbol, Dyna
78
76
if ( options . TryReadConversion ( type , Value ) is { } conversion )
79
77
{
80
78
if ( type . IsNullable ( ) )
81
- return CreateSignature ( type )
79
+ return CreateSignature ( type , options )
82
80
. CreateScope ( $ "return { Value } is not null ? ({ conversion } ) : null;")
83
81
. ToConversion ( ) ;
84
82
85
- return CreateSignature ( type )
83
+ return CreateSignature ( type , options )
86
84
. CreateScope ( $ "return { Value } is not null && ({ conversion } ) is {{ }} x ? x : throw { ExceptionHelper . NullExceptionMethod } ({ DataMember } );")
87
85
. ToConversion ( ) ;
88
86
}
89
87
90
88
return type . TypeIdentifier ( ) switch
91
89
{
92
- SingleGeneric singleGeneric when CreateSignature ( singleGeneric . TypeSymbol ) is var signature => singleGeneric . Type switch
90
+ SingleGeneric singleGeneric when CreateSignature ( singleGeneric . TypeSymbol , options ) is var signature => singleGeneric . Type switch
93
91
{
94
92
SingleGeneric . SupportedType . Nullable => signature
95
93
. CreateScope ( $ "return { Value } is not null and {{ NULL: false }} ? { InvokeUnmarshallMethod ( singleGeneric . T , Value , DataMember , options ) } : null;")
@@ -116,7 +114,7 @@ SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric() => signature
116
114
} ,
117
115
KeyValueGeneric { TKey . SpecialType : not SpecialType . System_String } keyValueGeneric => throw new ArgumentException ( "Only strings are supported for for TKey" ,
118
116
UncoveredConversionException ( keyValueGeneric , nameof ( CreateMethod ) ) ) ,
119
- KeyValueGeneric keyValueGeneric when CreateSignature ( keyValueGeneric . TypeSymbol ) is var signature => keyValueGeneric . Type switch
117
+ KeyValueGeneric keyValueGeneric when CreateSignature ( keyValueGeneric . TypeSymbol , options ) is var signature => keyValueGeneric . Type switch
120
118
{
121
119
KeyValueGeneric . SupportedType . Dictionary => signature
122
120
. CreateScope ( $ "return { Value } is {{ M: {{ }} x }} ? { AttributeValueUtilityFactory . ToDictionary } (x, { MarshallerOptions . ParamReference } , { DataMember } , static (a, o, d) => { InvokeUnmarshallMethod ( keyValueGeneric . TValue , "a" , "d" , options , "o" ) } ) : { Else ( keyValueGeneric . TypeSymbol ) } ;")
@@ -133,9 +131,9 @@ SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric() => signature
133
131
134
132
}
135
133
136
- private static string CreateSignature ( ITypeSymbol typeSymbol )
134
+ private static string CreateSignature ( ITypeSymbol typeSymbol , MarshallerOptions options )
137
135
{
138
- return $ "public static { typeSymbol . Representation ( ) . annotated } { GetDeserializationMethodName ( typeSymbol ) } (AttributeValue? { Value } , { MarshallerOptions . Name } { MarshallerOptions . ParamReference } , string? { DataMember } = null)";
136
+ return $ "public static { typeSymbol . Representation ( ) . annotated } { GetDeserializationMethodName ( typeSymbol ) } (AttributeValue? { Value } , { options . FullName } { MarshallerOptions . ParamReference } , string? { DataMember } = null)";
139
137
}
140
138
private static IEnumerable < string > CreateTypeContents ( IEnumerable < DynamoDBMarshallerArguments > arguments ,
141
139
Func < ITypeSymbol , DynamoDbDataMember [ ] > getDynamoDbProperties , MarshallerOptions options )
@@ -196,7 +194,7 @@ private static IEnumerable<string> ObjectAssignmentBlock(bool useParentheses, IE
196
194
197
195
internal static IEnumerable < string > RootSignature ( ITypeSymbol typeSymbol , string rootTypeName )
198
196
{
199
- return $ "public { rootTypeName } { Constants . DynamoDBGenerator . Marshaller . UnmarshalMethodName } (Dictionary<{ nameof ( String ) } , { Constants . AWSSDK_DynamoDBv2 . AttributeValue } > entity)". CreateScope (
197
+ return $ "public { rootTypeName } { Marshaller . UnmarshalMethodName } (Dictionary<{ nameof ( String ) } , { Constants . AWSSDK_DynamoDBv2 . AttributeValue } > entity)". CreateScope (
200
198
"ArgumentNullException.ThrowIfNull(entity);" ,
201
199
$ "return { UnMarshallerClass } .{ GetDeserializationMethodName ( typeSymbol ) } (entity, { MarshallerOptions . FieldReference } );") ;
202
200
}
0 commit comments