@@ -16,9 +16,9 @@ internal static IEnumerable<string> CreateClass(DynamoDBMarshallerArguments[] ar
1616 {
1717 return $ "file static class { ClassName } ". CreateScope ( TypeContent ( arguments , getDynamoDbProperties , options ) ) ;
1818 }
19- private static CodeFactory CreateDictionaryMethod ( ITypeSymbol typeSymbol , Func < ITypeSymbol , DynamoDbDataMember [ ] > fn , MarshallerOptions options )
19+ private static CodeFactory CreateDictionaryMethod ( TypeIdentifier typeIdentifier , Func < ITypeSymbol , DynamoDbDataMember [ ] > fn , MarshallerOptions options )
2020 {
21- var properties = fn ( typeSymbol )
21+ var properties = fn ( typeIdentifier . TypeSymbol )
2222 . Select ( x =>
2323 {
2424 var accessPattern = $ "{ ParamReference } .{ x . DataMember . Name } ";
@@ -34,16 +34,15 @@ private static CodeFactory CreateDictionaryMethod(ITypeSymbol typeSymbol, Func<I
3434 return (
3535 dictionaryAssignment : assignment ,
3636 capacityTernary : x . DataMember . IsNullable ? x . DataMember . Type . NotNullTernaryExpression ( in accessPattern , "1" , "0" ) : "1" ,
37- x . DataMember . Type
37+ x . DataMember
3838 ) ;
3939 } )
4040 . ToArray ( ) ;
4141
42- var isNullable = typeSymbol . IsNullable ( ) ;
4342 var enumerable = Enumerable . Empty < string > ( ) ;
44- if ( isNullable )
43+ if ( typeIdentifier . IsNullable )
4544 enumerable = $ "if ({ ParamReference } is null)". CreateScope ( "return null;" ) ;
46- else if ( typeSymbol . IsReferenceType )
45+ else if ( typeIdentifier . TypeSymbol . IsReferenceType )
4746 enumerable = $ "if ({ ParamReference } is null)". CreateScope ( $ "throw { ExceptionHelper . NullExceptionMethod } ({ DataMember } );") ;
4847
4948 var body =
@@ -52,67 +51,66 @@ private static CodeFactory CreateDictionaryMethod(ITypeSymbol typeSymbol, Func<I
5251 . Append ( $ "return { DictionaryReference } ;") ) ;
5352
5453 var code =
55- $ "public static Dictionary<string, AttributeValue>{ ( isNullable ? '?' : null ) } { GetSerializationMethodName ( typeSymbol ) } ({ typeSymbol . Representation ( ) . annotated } { ParamReference } , { options . FullName } { MarshallerOptions . ParamReference } , string? { DataMember } = null)"
54+ $ "public static Dictionary<string, AttributeValue>{ ( typeIdentifier . IsNullable ? '?' : null ) } { GetSerializationMethodName ( typeIdentifier . TypeSymbol ) } ({ typeIdentifier . AnnotatedRepresenation } { ParamReference } , { options . FullName } { MarshallerOptions . ParamReference } , string? { DataMember } = null)"
5655 . CreateScope ( body ) ;
5756
58- return new CodeFactory ( code , properties . Select ( y => y . Type ) ) ;
57+ return new CodeFactory ( code , properties . Select ( y => y . DataMember . TypeIdentifier ) ) ;
5958
6059 }
6160
6261 private static IEnumerable < string > TypeContent ( DynamoDBMarshallerArguments [ ] arguments , Func < ITypeSymbol , DynamoDbDataMember [ ] > getDynamoDbProperties , MarshallerOptions options )
6362 {
64- var hashset = new HashSet < ITypeSymbol > ( SymbolEqualityComparer . IncludeNullability ) ;
63+ var hashset = new HashSet < TypeIdentifier > ( TypeIdentifier . Nullable ) ;
6564
6665 return arguments . SelectMany ( x => CodeFactory
6766 . Create (
68- x . EntityTypeSymbol ,
67+ x . EntityTypeSymbol . TypeIdentifier ( ) ,
6968 y => CreateMethod ( y , getDynamoDbProperties , options ) ,
7069 hashset
7170 )
72- . Concat ( CodeFactory . Create ( x . ArgumentType , y => CreateMethod ( y , getDynamoDbProperties , options ) ,
71+ . Concat ( CodeFactory . Create ( x . ArgumentType . TypeIdentifier ( ) , y => CreateMethod ( y , getDynamoDbProperties , options ) ,
7372 hashset ) )
7473 )
7574 . Concat ( KeyMarshaller . CreateKeys ( arguments , getDynamoDbProperties , options ) ) ;
7675 }
77- private static CodeFactory CreateMethod ( ITypeSymbol type , Func < ITypeSymbol , DynamoDbDataMember [ ] > fn , MarshallerOptions options )
76+ private static CodeFactory CreateMethod ( TypeIdentifier typeIdentifier , Func < ITypeSymbol , DynamoDbDataMember [ ] > fn , MarshallerOptions options )
7877 {
79- if ( options . TryWriteConversion ( type , ParamReference ) is { } conversion )
78+ if ( options . TryWriteConversion ( typeIdentifier . TypeSymbol , ParamReference ) is { } conversion )
8079 {
81- return type switch
80+ return typeIdentifier . TypeSymbol switch
8281 {
83- { IsValueType : true } => type switch
82+ { IsValueType : true } => typeIdentifier . TypeSymbol switch
8483 {
85- { OriginalDefinition . SpecialType : SpecialType . System_Nullable_T } => CreateSignature ( type , options )
84+ { OriginalDefinition . SpecialType : SpecialType . System_Nullable_T } => CreateSignature ( typeIdentifier , options )
8685 . CreateScope ( $ "if ({ ParamReference } is null)"
8786 . CreateScope ( "return null;" )
8887 . Append ( $ "return { conversion } ;")
8988 )
9089 . ToConversion ( ) ,
91- _ => CreateSignature ( type , options )
90+ _ => CreateSignature ( typeIdentifier , options )
9291 . CreateScope ( $ "return { conversion } ;")
9392 . ToConversion ( )
9493 } ,
95- { IsReferenceType : true } => type switch
94+ { IsReferenceType : true } => typeIdentifier . TypeSymbol switch
9695 {
97- { NullableAnnotation : NullableAnnotation . None or NullableAnnotation . Annotated } => CreateSignature (
98- type , options )
96+ { NullableAnnotation : NullableAnnotation . None or NullableAnnotation . Annotated } => CreateSignature ( typeIdentifier , options )
9997 . CreateScope ( $ "if ({ ParamReference } is null)". CreateScope ( "return null;" )
10098 . Append ( $ "return { conversion } ;") )
10199 . ToConversion ( ) ,
102- _ => CreateSignature ( type , options )
100+ _ => CreateSignature ( typeIdentifier , options )
103101 . CreateScope (
104102 $ "if ({ ParamReference } is null)". CreateScope ( $ "throw { ExceptionHelper . NullExceptionMethod } ({ DataMember } );") . Append ( $ "return { conversion } ;")
105103 )
106104 . ToConversion ( )
107105 } ,
108106 _ => throw new ArgumentException (
109- $ "Neither ValueType or ReferenceType could be resolved for conversion. type '{ type . ToDisplayString ( ) } '.")
107+ $ "Neither ValueType or ReferenceType could be resolved for conversion. type '{ typeIdentifier . TypeSymbol . ToDisplayString ( ) } '.")
110108 } ;
111109 }
112110
113- return type . TypeIdentifier ( ) switch
111+ return typeIdentifier switch
114112 {
115- SingleGeneric singleGeneric when CreateSignature ( singleGeneric . TypeSymbol , options ) is var signature => singleGeneric . Type switch
113+ SingleGeneric singleGeneric when CreateSignature ( singleGeneric , options ) is var signature => singleGeneric . Type switch
116114 {
117115 SingleGeneric . SupportedType . Nullable => signature
118116 . CreateScope (
@@ -161,7 +159,7 @@ SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric()
161159 } ,
162160 KeyValueGeneric { TKey . SpecialType : not SpecialType . System_String } keyValueGeneric => throw new ArgumentException ( "Only strings are supported for for TKey" ,
163161 UncoveredConversionException ( keyValueGeneric , nameof ( CreateMethod ) ) ) ,
164- KeyValueGeneric keyValueGeneric when CreateSignature ( keyValueGeneric . TypeSymbol , options ) is var signature => keyValueGeneric . Type switch
162+ KeyValueGeneric keyValueGeneric when CreateSignature ( keyValueGeneric , options ) is var signature => keyValueGeneric . Type switch
165163 {
166164 KeyValueGeneric . SupportedType . Dictionary => signature
167165 . CreateScope (
@@ -179,17 +177,18 @@ SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric()
179177 . ToConversion ( keyValueGeneric . TValue ) ,
180178 _ => throw UncoveredConversionException ( keyValueGeneric , nameof ( CreateMethod ) )
181179 } ,
182- UnknownType unknownType => CreateDictionaryMethod ( unknownType . TypeSymbol , fn , options ) ,
183- var typeIdentifier => throw UncoveredConversionException ( typeIdentifier , nameof ( CreateMethod ) )
180+ UnknownType unknownType => CreateDictionaryMethod ( unknownType , fn , options ) ,
181+ _ => throw UncoveredConversionException ( typeIdentifier , nameof ( CreateMethod ) )
184182
185183 } ;
186184
187185 }
188- private static string CreateSignature ( ITypeSymbol typeSymbol , MarshallerOptions options )
186+ private static string CreateSignature ( TypeIdentifier typeIdentifier , MarshallerOptions options )
189187 {
190- return typeSymbol . IsNullable ( )
191- ? $ "public static { Constants . AWSSDK_DynamoDBv2 . AttributeValue } ? { GetSerializationMethodName ( typeSymbol ) } ({ typeSymbol . Representation ( ) . annotated } { ParamReference } , { options . FullName } { MarshallerOptions . ParamReference } , string? { DataMember } = null)"
192- : $ "public static { Constants . AWSSDK_DynamoDBv2 . AttributeValue } { GetSerializationMethodName ( typeSymbol ) } ({ typeSymbol . Representation ( ) . annotated } { ParamReference } , { options . FullName } { MarshallerOptions . ParamReference } , string? { DataMember } = null)";
188+ var typeSymbol = typeIdentifier . TypeSymbol ;
189+ return typeIdentifier . IsNullable
190+ ? $ "public static { Constants . AWSSDK_DynamoDBv2 . AttributeValue } ? { GetSerializationMethodName ( typeSymbol ) } ({ typeIdentifier . AnnotatedRepresenation } { ParamReference } , { options . FullName } { MarshallerOptions . ParamReference } , string? { DataMember } = null)"
191+ : $ "public static { Constants . AWSSDK_DynamoDBv2 . AttributeValue } { GetSerializationMethodName ( typeSymbol ) } ({ typeIdentifier . AnnotatedRepresenation } { ParamReference } , { options . FullName } { MarshallerOptions . ParamReference } , string? { DataMember } = null)";
193192 }
194193
195194 private static IEnumerable < string > InitializeDictionary ( IEnumerable < string > capacityCalculations )
0 commit comments