@@ -22,12 +22,12 @@ private void Emit_CoreBindingHelper()
22
22
_writer . WriteLine ( ) ;
23
23
_emitBlankLineBeforeNextStatement = false ;
24
24
25
- EmitStartScope ( $ "namespace { ProjectName } ") ;
25
+ EmitStartBlock ( $ "namespace { ProjectName } ") ;
26
26
EmitHelperUsingStatements ( ) ;
27
27
28
28
_writer . WriteLine ( ) ;
29
29
30
- EmitStartScope ( $$ """
30
+ EmitStartBlock ( $$ """
31
31
/// <summary>Provide core binding logic.</summary>
32
32
{{ GetGeneratedCodeAttributeSrc ( ) }}
33
33
file static class {{ Identifier . CoreBindingHelper }}
@@ -41,8 +41,8 @@ file static class {{Identifier.CoreBindingHelper}}
41
41
EmitInitializeMethods ( ) ;
42
42
EmitHelperMethods ( ) ;
43
43
44
- EmitEndScope ( ) ; // End helper class.
45
- EmitEndScope ( ) ; // End namespace.
44
+ EmitEndBlock ( ) ; // End helper class.
45
+ EmitEndBlock ( ) ; // End namespace.
46
46
}
47
47
48
48
private void EmitHelperUsingStatements ( )
@@ -87,7 +87,7 @@ private void EmitGetCoreMethod()
87
87
}
88
88
89
89
EmitBlankLineIfRequired ( ) ;
90
- EmitStartScope ( $ "public static object? { nameof ( MethodsToGen_CoreBindingHelper . GetCore ) } (this { Identifier . IConfiguration } { Identifier . configuration } , Type { Identifier . type } , Action<{ Identifier . BinderOptions } >? { Identifier . configureOptions } )") ;
90
+ EmitStartBlock ( $ "public static object? { nameof ( MethodsToGen_CoreBindingHelper . GetCore ) } (this { Identifier . IConfiguration } { Identifier . configuration } , Type { Identifier . type } , Action<{ Identifier . BinderOptions } >? { Identifier . configureOptions } )") ;
91
91
92
92
EmitCheckForNullArgument_WithBlankLine ( Identifier . configuration ) ;
93
93
@@ -100,7 +100,7 @@ private void EmitGetCoreMethod()
100
100
{
101
101
TypeSpecKind kind = type . SpecKind ;
102
102
103
- EmitStartScope ( $ "if (type == typeof({ type . MinimalDisplayString } ))") ;
103
+ EmitStartBlock ( $ "if (type == typeof({ type . MinimalDisplayString } ))") ;
104
104
105
105
if ( type is ParsableFromStringSpec stringParsableType )
106
106
{
@@ -119,12 +119,12 @@ private void EmitGetCoreMethod()
119
119
_writer . WriteLine ( $ "return { Identifier . obj } ;") ;
120
120
}
121
121
122
- EmitEndScope ( ) ;
122
+ EmitEndBlock ( ) ;
123
123
_writer . WriteLine ( ) ;
124
124
}
125
125
126
126
Emit_NotSupportedException_TypeNotDetectedAsInput ( ) ;
127
- EmitEndScope ( ) ;
127
+ EmitEndBlock ( ) ;
128
128
_emitBlankLineBeforeNextStatement = true ;
129
129
}
130
130
@@ -136,7 +136,7 @@ private void EmitGetValueCoreMethod()
136
136
}
137
137
138
138
EmitBlankLineIfRequired ( ) ;
139
- EmitStartScope ( $ "public static object? { nameof ( MethodsToGen_CoreBindingHelper . GetValueCore ) } (this { Identifier . IConfiguration } { Identifier . configuration } , Type { Identifier . type } , string { Identifier . key } )") ;
139
+ EmitStartBlock ( $ "public static object? { nameof ( MethodsToGen_CoreBindingHelper . GetValueCore ) } (this { Identifier . IConfiguration } { Identifier . configuration } , Type { Identifier . type } , string { Identifier . key } )") ;
140
140
141
141
EmitCheckForNullArgument_WithBlankLine ( Identifier . configuration ) ;
142
142
_writer . WriteLine ( $@ "{ Identifier . IConfigurationSection } { Identifier . section } = { GetSectionFromConfigurationExpression ( Identifier . key , addQuotes : false ) } ;") ;
@@ -153,7 +153,7 @@ private void EmitGetValueCoreMethod()
153
153
154
154
foreach ( TypeSpec type in targetTypes )
155
155
{
156
- EmitStartScope ( $ "if ({ Identifier . type } == typeof({ type . MinimalDisplayString } ))") ;
156
+ EmitStartBlock ( $ "if ({ Identifier . type } == typeof({ type . MinimalDisplayString } ))") ;
157
157
158
158
EmitBindLogicFromString (
159
159
( ParsableFromStringSpec ) type . EffectiveType ,
@@ -163,12 +163,12 @@ private void EmitGetValueCoreMethod()
163
163
checkForNullSectionValue : false ,
164
164
useIncrementalStringValueIdentifier : false ) ;
165
165
166
- EmitEndScope ( ) ;
166
+ EmitEndBlock ( ) ;
167
167
_writer . WriteLine ( ) ;
168
168
}
169
169
170
170
_writer . WriteLine ( "return null;" ) ;
171
- EmitEndScope ( ) ;
171
+ EmitEndBlock ( ) ;
172
172
_emitBlankLineBeforeNextStatement = true ;
173
173
}
174
174
@@ -181,7 +181,7 @@ private void EmitBindCoreUntypedMethod()
181
181
182
182
EmitBlankLineIfRequired ( ) ;
183
183
184
- EmitStartScope ( $ "public static void { nameof ( MethodsToGen_CoreBindingHelper . BindCoreUntyped ) } (this { Identifier . IConfiguration } { Identifier . configuration } , object { Identifier . obj } , Type { Identifier . type } , { MinimalDisplayString . NullableActionOfBinderOptions } { Identifier . configureOptions } )") ;
184
+ EmitStartBlock ( $ "public static void { nameof ( MethodsToGen_CoreBindingHelper . BindCoreUntyped ) } (this { Identifier . IConfiguration } { Identifier . configuration } , object { Identifier . obj } , Type { Identifier . type } , { MinimalDisplayString . NullableActionOfBinderOptions } { Identifier . configureOptions } )") ;
185
185
186
186
EmitCheckForNullArgument_WithBlankLine ( Identifier . configuration ) ;
187
187
@@ -192,7 +192,7 @@ private void EmitBindCoreUntypedMethod()
192
192
193
193
foreach ( TypeSpec type in targetTypes )
194
194
{
195
- EmitStartScope ( $ "if (type == typeof({ type . MinimalDisplayString } ))") ;
195
+ EmitStartBlock ( $ "if (type == typeof({ type . MinimalDisplayString } ))") ;
196
196
197
197
TypeSpec effectiveType = type . EffectiveType ;
198
198
if ( ! EmitInitException ( effectiveType ) )
@@ -202,12 +202,12 @@ private void EmitBindCoreUntypedMethod()
202
202
_writer . WriteLine ( $ "return;") ;
203
203
}
204
204
205
- EmitEndScope ( ) ;
205
+ EmitEndBlock ( ) ;
206
206
_writer . WriteLine ( ) ;
207
207
}
208
208
209
209
Emit_NotSupportedException_TypeNotDetectedAsInput ( ) ;
210
- EmitEndScope ( ) ;
210
+ EmitEndBlock ( ) ;
211
211
_emitBlankLineBeforeNextStatement = true ;
212
212
}
213
213
@@ -231,7 +231,7 @@ private void EmitBindCoreMethod(TypeSpec type)
231
231
Debug . Assert ( type . CanInitialize ) ;
232
232
233
233
string objParameterExpression = $ "ref { type . MinimalDisplayString } { Identifier . obj } ";
234
- EmitStartScope ( @$ "public static void { nameof ( MethodsToGen_CoreBindingHelper . BindCore ) } ({ Identifier . IConfiguration } { Identifier . configuration } , { objParameterExpression } , { Identifier . BinderOptions } ? { Identifier . binderOptions } )") ;
234
+ EmitStartBlock ( @$ "public static void { nameof ( MethodsToGen_CoreBindingHelper . BindCore ) } ({ Identifier . IConfiguration } { Identifier . configuration } , { objParameterExpression } , { Identifier . BinderOptions } ? { Identifier . binderOptions } )") ;
235
235
236
236
EmitCheckForNullArgument_WithBlankLine_IfRequired ( type . IsValueType ) ;
237
237
@@ -257,7 +257,7 @@ private void EmitBindCoreMethod(TypeSpec type)
257
257
EmitBindCoreImplForObject ( ( ObjectSpec ) effectiveType ) ;
258
258
}
259
259
260
- EmitEndScope ( ) ;
260
+ EmitEndBlock ( ) ;
261
261
}
262
262
263
263
private void EmitInitializeMethods ( )
@@ -282,7 +282,7 @@ private void EmitInitializeMethod(ObjectSpec type)
282
282
List < string > ctorArgList = new ( ) ;
283
283
string displayString = type . MinimalDisplayString ;
284
284
285
- EmitStartScope ( $ "public static { type . MinimalDisplayString } { GetInitalizeMethodDisplayString ( type ) } ({ Identifier . IConfiguration } { Identifier . configuration } , { Identifier . BinderOptions } ? { Identifier . binderOptions } )") ;
285
+ EmitStartBlock ( $ "public static { type . MinimalDisplayString } { GetInitalizeMethodDisplayString ( type ) } ({ Identifier . IConfiguration } { Identifier . configuration } , { Identifier . BinderOptions } ? { Identifier . binderOptions } )") ;
286
286
_emitBlankLineBeforeNextStatement = false ;
287
287
288
288
foreach ( ParameterSpec parameter in ctorParams )
@@ -316,17 +316,17 @@ private void EmitInitializeMethod(ObjectSpec type)
316
316
}
317
317
else
318
318
{
319
- EmitStartScope ( returnExpression ) ;
319
+ EmitStartBlock ( returnExpression ) ;
320
320
foreach ( PropertySpec property in initOnlyProps )
321
321
{
322
322
string propertyName = property . Name ;
323
323
_writer . WriteLine ( $@ "{ propertyName } = { propertyName } ,") ;
324
324
}
325
- EmitEndScope ( extra : ";" ) ;
325
+ EmitEndBlock ( endBraceTrailingSource : ";" ) ;
326
326
}
327
327
328
328
// End method.
329
- EmitEndScope ( ) ;
329
+ EmitEndBlock ( ) ;
330
330
_emitBlankLineBeforeNextStatement = true ;
331
331
332
332
void EmitBindImplForMember ( MemberSpec member )
@@ -591,17 +591,14 @@ private void EmitPrimitiveParseMethod(ParsableFromStringSpec type)
591
591
}
592
592
}
593
593
594
- EmitStartScope ( $ "public static { typeDisplayString } { type . ParseMethodName } (string { Identifier . value } , Func<string?> { Identifier . getPath } )") ;
595
- _writer . WriteLine ( $$ """
594
+ string exceptionArg1 = string . Format ( ExceptionMessages . FailedBinding , $ "{{{Identifier.getPath}()}}", $ "{{typeof({ typeDisplayString } )}}") ;
595
+
596
+ EmitStartBlock ( $ "public static { typeDisplayString } { type . ParseMethodName } (string { Identifier . value } , Func<string?> { Identifier . getPath } )") ;
597
+ EmitEndBlock ( $$ """
596
598
try
597
599
{
598
600
return {{ parsedValueExpr }} ;
599
601
}
600
- """ ) ;
601
-
602
- string exceptionArg1 = string . Format ( ExceptionMessages . FailedBinding , $ "{{{Identifier.getPath}()}}", $ "{{typeof({ typeDisplayString } )}}") ;
603
-
604
- EmitEndScope ( $$ """
605
602
catch ({{ innerExceptionTypeDisplayString }} {{ Identifier . exception }} )
606
603
{
607
604
throw new {{ GetInvalidOperationDisplayName ( ) }} ($"{{ exceptionArg1 }} ", {{ Identifier . exception }} );
@@ -629,7 +626,7 @@ private void EmitPopulationImplForEnumerableWithAdd(EnumerableSpec type)
629
626
{
630
627
EmitCollectionCastIfRequired ( type , out string objIdentifier ) ;
631
628
632
- Emit_Foreach_Section_In_ConfigChildren_StartScope ( ) ;
629
+ Emit_Foreach_Section_In_ConfigChildren_StartBlock ( ) ;
633
630
634
631
TypeSpec elementType = type . ElementType ;
635
632
@@ -649,14 +646,14 @@ private void EmitPopulationImplForEnumerableWithAdd(EnumerableSpec type)
649
646
_writer . WriteLine ( $ "{ objIdentifier } .{ Identifier . Add } ({ Identifier . value } );") ;
650
647
}
651
648
652
- EmitEndScope ( ) ;
649
+ EmitEndBlock ( ) ;
653
650
}
654
651
655
652
private void EmitBindCoreImplForDictionary ( DictionarySpec type )
656
653
{
657
654
EmitCollectionCastIfRequired ( type , out string objIdentifier ) ;
658
655
659
- Emit_Foreach_Section_In_ConfigChildren_StartScope ( ) ;
656
+ Emit_Foreach_Section_In_ConfigChildren_StartBlock ( ) ;
660
657
661
658
ParsableFromStringSpec keyType = type . KeyType ;
662
659
TypeSpec elementType = type . ElementType ;
@@ -706,9 +703,9 @@ void Emit_BindAndAddLogic_ForElement(string parsedKeyExpr)
706
703
conditionToUseExistingElement += $ " && { expressionForElementIsNotNull } ";
707
704
}
708
705
709
- EmitStartScope ( $ "if (!({ conditionToUseExistingElement } ))") ;
706
+ EmitStartBlock ( $ "if (!({ conditionToUseExistingElement } ))") ;
710
707
EmitObjectInit ( elementType , Identifier . element , InitializationKind . SimpleAssignment , Identifier . section ) ;
711
- EmitEndScope ( ) ;
708
+ EmitEndBlock ( ) ;
712
709
713
710
if ( elementType is CollectionSpec { InitializationStrategy : InitializationStrategy . ParameterizedConstructor or InitializationStrategy . ToEnumerableMethod } collectionSpec )
714
711
{
@@ -732,7 +729,7 @@ void Emit_BindAndAddLogic_ForElement(string parsedKeyExpr)
732
729
}
733
730
}
734
731
735
- EmitEndScope ( ) ;
732
+ EmitEndBlock ( ) ;
736
733
}
737
734
738
735
private void EmitBindCoreImplForObject ( ObjectSpec type )
@@ -802,15 +799,15 @@ private bool EmitBindImplForMember(
802
799
string sectionValidationCall = $ "{ Identifier . AsConfigWithChildren } ({ sectionParseExpr } )";
803
800
string sectionIdentifier = GetIncrementalIdentifier ( Identifier . section ) ;
804
801
805
- EmitStartScope ( $ "if ({ sectionValidationCall } is { Identifier . IConfigurationSection } { sectionIdentifier } )") ;
802
+ EmitStartBlock ( $ "if ({ sectionValidationCall } is { Identifier . IConfigurationSection } { sectionIdentifier } )") ;
806
803
807
804
bool success = ! EmitInitException ( effectiveMemberType ) ;
808
805
if ( success )
809
806
{
810
807
EmitBindCoreCallForMember ( member , memberAccessExpr , sectionIdentifier , canSet ) ;
811
808
}
812
809
813
- EmitEndScope ( ) ;
810
+ EmitEndBlock ( ) ;
814
811
return success ;
815
812
}
816
813
@@ -901,8 +898,8 @@ private void EmitCollectionCastIfRequired(CollectionSpec type, out string objIde
901
898
}
902
899
}
903
900
904
- private void Emit_Foreach_Section_In_ConfigChildren_StartScope ( ) =>
905
- EmitStartScope ( $ "foreach ({ Identifier . IConfigurationSection } { Identifier . section } in { Identifier . configuration } .{ Identifier . GetChildren } ())") ;
901
+ private void Emit_Foreach_Section_In_ConfigChildren_StartBlock ( ) =>
902
+ EmitStartBlock ( $ "foreach ({ Identifier . IConfigurationSection } { Identifier . section } in { Identifier . configuration } .{ Identifier . GetChildren } ())") ;
906
903
907
904
private static string GetSectionPathFromConfigurationExpression ( string configurationKeyName )
908
905
=> $@ "{ GetSectionFromConfigurationExpression ( configurationKeyName ) } .{ Identifier . Path } ";
0 commit comments