@@ -19,11 +19,11 @@ private static IEnumerable<string> CreateAssignment(string validateReference, st
19
19
var expression = $ "{ keyReference } is { expectedType } {{ }} { reference } ";
20
20
21
21
var innerContent = $ "if ({ expression } ) "
22
- . CreateBlock ( $@ "{ DictionaryName } .Add(""{ dataMember . AttributeName } "", { Marshaller . InvokeMarshallerMethod ( dataMember . DataMember . Type , reference , $ "nameof({ keyReference } )", options ) } );")
23
- . Concat ( $ "else if ({ keyReference } is null) ". CreateBlock ( $@ "throw { ExceptionHelper . KeysArgumentNullExceptionMethod } (""{ dataMember . DataMember . Name } "", ""{ keyReference } "");") )
24
- . Concat ( "else" . CreateBlock ( $@ "throw { ExceptionHelper . KeysInvalidConversionExceptionMethod } (""{ dataMember . DataMember . Name } "", ""{ keyReference } "", { keyReference } , ""{ expectedType } "");") ) ;
22
+ . CreateScope ( $@ "{ DictionaryName } .Add(""{ dataMember . AttributeName } "", { Marshaller . InvokeMarshallerMethod ( dataMember . DataMember . Type , reference , $ "nameof({ keyReference } )", options ) } );")
23
+ . Concat ( $ "else if ({ keyReference } is null) ". CreateScope ( $@ "throw { ExceptionHelper . KeysArgumentNullExceptionMethod } (""{ dataMember . DataMember . Name } "", ""{ keyReference } "");") )
24
+ . Concat ( "else" . CreateScope ( $@ "throw { ExceptionHelper . KeysInvalidConversionExceptionMethod } (""{ dataMember . DataMember . Name } "", ""{ keyReference } "", { keyReference } , ""{ expectedType } "");") ) ;
25
25
26
- return $ "if({ validateReference } )". CreateBlock ( innerContent ) ;
26
+ return $ "if({ validateReference } )". CreateScope ( innerContent ) ;
27
27
28
28
}
29
29
private static IEnumerable < string > CreateBody ( ITypeSymbol typeSymbol , Func < ITypeSymbol , IReadOnlyList < DynamoDbDataMember > > fn , MarshallerOptions options )
@@ -39,17 +39,17 @@ private static IEnumerable<string> CreateBody(ITypeSymbol typeSymbol, Func<IType
39
39
yield return $ "var { DictionaryName } = new Dictionary<string, AttributeValue>(2);";
40
40
41
41
var switchBody = GetAssignments ( keyStructure . Value , options )
42
- . SelectMany ( x => $ "case { ( x . IndexName is null ? "null" : @$ """{ x . IndexName } """)}:". CreateBlock ( x . assignments ) . Append ( "break;" ) )
42
+ . SelectMany ( x => $ "case { ( x . IndexName is null ? "null" : @$ """{ x . IndexName } """)}:". CreateScope ( x . assignments ) . Append ( "break;" ) )
43
43
. Append ( $ "default: throw { ExceptionHelper . MissMatchedIndexNameExceptionMethod } (nameof(index), index);") ;
44
44
45
- foreach ( var s in "switch (index)" . CreateBlock ( switchBody ) )
45
+ foreach ( var s in "switch (index)" . CreateScope ( switchBody ) )
46
46
yield return s;
47
47
48
48
var validateSwitch = $"if ( { EnforcePkReference } && { EnforceRkReference } && { DictionaryName } . Count == 2 ) "
49
- . CreateBlock ( $ "return { DictionaryName } ;")
50
- . Concat ( $ "if ({ EnforcePkReference } && { EnforceRkReference } is false && { DictionaryName } .Count == 1)". CreateBlock ( $ "return { DictionaryName } ;") )
51
- . Concat ( $ "if ({ EnforcePkReference } is false && { EnforceRkReference } && { DictionaryName } .Count == 1)". CreateBlock ( $ "return { DictionaryName } ;") )
52
- . Concat ( $ "if ({ EnforcePkReference } && { EnforceRkReference } && { DictionaryName } .Count == 1)". CreateBlock ( $ "throw { ExceptionHelper . KeysMissingDynamoDBAttributeExceptionMethod } ({ PkReference } , { RkReference } );") )
49
+ . CreateScope ( $ "return { DictionaryName } ;")
50
+ . Concat ( $ "if ({ EnforcePkReference } && { EnforceRkReference } is false && { DictionaryName } .Count == 1)". CreateScope ( $ "return { DictionaryName } ;") )
51
+ . Concat ( $ "if ({ EnforcePkReference } is false && { EnforceRkReference } && { DictionaryName } .Count == 1)". CreateScope ( $ "return { DictionaryName } ;") )
52
+ . Concat ( $ "if ({ EnforcePkReference } && { EnforceRkReference } && { DictionaryName } .Count == 1)". CreateScope ( $ "throw { ExceptionHelper . KeysMissingDynamoDBAttributeExceptionMethod } ({ PkReference } , { RkReference } );") )
53
53
. Append ( $ "throw { ExceptionHelper . ShouldNeverHappenExceptionMethod } ();") ;
54
54
55
55
foreach ( var s in validateSwitch )
@@ -93,11 +93,11 @@ private static IEnumerable<string> MissingAssigment(string validateReference, st
93
93
{
94
94
95
95
var expression = $"{validateReference} && {keyReference} is not null" ;
96
- return $"if ({expression})" . CreateBlock ( $ "throw { ExceptionHelper . KeysValueWithNoCorrespondenceMethod } (\" { keyReference } \" , { keyReference } );") ;
96
+ return $"if ({expression})" . CreateScope ( $ "throw { ExceptionHelper . KeysValueWithNoCorrespondenceMethod } (\" { keyReference } \" , { keyReference } );") ;
97
97
}
98
98
internal static IEnumerable < string > IndexKeyMarshallerRootSignature ( ITypeSymbol typeSymbol )
99
99
{
100
- return $"public {Constants.DynamoDBGenerator.Marshaller.IndexKeyMarshallerInterface} IndexKeyMarshaller(string index)" . CreateBlock (
100
+ return $"public {Constants.DynamoDBGenerator.Marshaller.IndexKeyMarshallerInterface} IndexKeyMarshaller(string index)" . CreateScope (
101
101
"ArgumentNullException.ThrowIfNull(index);" ,
102
102
$ "return new { IndexKeyMarshallerImplementationTypeName } ((pk, rk, ipk, irk, dm) => { MethodName ( typeSymbol ) } ({ MarshallerOptions . FieldReference } , pk, rk, ipk, irk, dm), index);"
103
103
) ;
@@ -114,7 +114,7 @@ private static Conversion StaticAttributeValueDictionaryKeys(ITypeSymbol typeSym
114
114
{
115
115
116
116
var code = $"private static Dictionary<string, AttributeValue> {MethodName(typeSymbol)}({MarshallerOptions.Name} {MarshallerOptions.ParamReference}, object? {PkReference}, object? {RkReference}, bool {EnforcePkReference}, bool {EnforceRkReference}, string? index = null)"
117
- . CreateBlock ( CreateBody ( typeSymbol , fn , options ) ) ;
117
+ . CreateScope ( CreateBody ( typeSymbol , fn , options ) ) ;
118
118
119
119
return new Conversion ( code ) ;
120
120
0 commit comments