@@ -94,7 +94,7 @@ private static CompilationUnitSyntax GenerateStandardCompilationUnit(SourceProdu
9494 ClassDeclaration ( context . ClassName ! )
9595 . WithLeadingTrivia ( NullableEnableTriviaList )
9696 . WithModifiers ( InternalAbstractPartialTokenList )
97- . WithMembers ( List < MemberDeclarationSyntax > (
97+ . WithMembers ( List (
9898 [
9999 .. GenerateSharedMemberDeclarations ( context ) ,
100100 .. GenerateEntryMemberDeclarations ( production , context )
@@ -111,7 +111,7 @@ private static IEnumerable<MemberDeclarationSyntax> GenerateSharedMemberDeclarat
111111 // get => field ??= new("${namespace}", typeof(${className}).Assembly);
112112 // }
113113 yield return PropertyDeclaration ( TypeOfSystemResourcesResourceManager , Identifier ( "ResourceManager" ) )
114- . WithAttributeLists ( List < AttributeListSyntax > (
114+ . WithAttributeLists ( List (
115115 [
116116 AttributeList ( SingletonSeparatedList ( Attribute ( NameOfSystemDiagnosticsCodeAnalysisMaybeNull ) ) )
117117 . WithTarget ( AttributeTargetSpecifier ( FieldKeyword ) ) ,
@@ -148,7 +148,7 @@ private static IEnumerable<MemberDeclarationSyntax> GenerateSharedMemberDeclarat
148148 . WithAccessorList ( GetAndSetAccessorList ) ;
149149
150150 // [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(defaultValue))]
151- // public static object? GetObject(global::System.Globalization.CultureInfo? culture, string name , object? defaultValue)
151+ // public static object? GetObject(string name, global::System.Globalization.CultureInfo? culture, object? defaultValue)
152152 // {
153153 // return ResourceManager.GetObject(name, culture ?? Culture) ?? defaultValue;
154154 // }
@@ -158,8 +158,8 @@ private static IEnumerable<MemberDeclarationSyntax> GenerateSharedMemberDeclarat
158158 . WithModifiers ( PublicStaticTokenList )
159159 . WithParameterList ( ParameterList ( SeparatedList (
160160 [
161- Parameter ( NullableType ( TypeOfSystemGlobalizationCultureInfo ) , Identifier ( "culture" ) ) ,
162161 Parameter ( StringType , Identifier ( "name" ) ) ,
162+ Parameter ( NullableType ( TypeOfSystemGlobalizationCultureInfo ) , Identifier ( "culture" ) ) ,
163163 Parameter ( NullableObjectType , Identifier ( "defaultValue" ) )
164164 ] ) ) )
165165 . WithBody ( Block ( SingletonList (
@@ -174,29 +174,29 @@ private static IEnumerable<MemberDeclarationSyntax> GenerateSharedMemberDeclarat
174174 ] ) ) ) ,
175175 IdentifierName ( "defaultValue" ) ) ) ) ) ) ;
176176
177- // public static object? GetObject(global::System.Globalization.CultureInfo? culture, string name )
177+ // public static object? GetObject(string name, global::System.Globalization.CultureInfo? culture)
178178 // {
179- // return GetObject(culture, name, default);
179+ // return GetObject(name, culture, default);
180180 // }
181181 yield return MethodDeclaration ( NullableObjectType , Identifier ( "GetObject" ) )
182182 . WithModifiers ( PublicStaticTokenList )
183183 . WithParameterList ( ParameterList ( SeparatedList (
184184 [
185- Parameter ( NullableType ( TypeOfSystemGlobalizationCultureInfo ) , Identifier ( "culture " ) ) ,
186- Parameter ( StringType , Identifier ( "name " ) )
185+ Parameter ( StringType , Identifier ( "name " ) ) ,
186+ Parameter ( NullableType ( TypeOfSystemGlobalizationCultureInfo ) , Identifier ( "culture " ) )
187187 ] ) ) )
188188 . WithBody ( Block ( SingletonList (
189189 ReturnStatement ( InvocationExpression ( IdentifierName ( "GetObject" ) )
190190 . WithArgumentList ( ArgumentList ( SeparatedList (
191191 [
192- Argument ( IdentifierName ( "culture" ) ) ,
193192 Argument ( IdentifierName ( "name" ) ) ,
194- Argument ( DefaultLiteralExpression ) ,
193+ Argument ( IdentifierName ( "culture" ) ) ,
194+ Argument ( DefaultLiteralExpression )
195195 ] ) ) ) ) ) ) ) ;
196196
197197 // public static object? GetObject(string name)
198198 // {
199- // return GetObject(default, name , default);
199+ // return GetObject(name, default , default);
200200 // }
201201 yield return MethodDeclaration ( NullableObjectType , Identifier ( "GetObject" ) )
202202 . WithModifiers ( PublicStaticTokenList )
@@ -206,15 +206,15 @@ private static IEnumerable<MemberDeclarationSyntax> GenerateSharedMemberDeclarat
206206 ReturnStatement ( InvocationExpression ( IdentifierName ( "GetObject" ) )
207207 . WithArgumentList ( ArgumentList ( SeparatedList (
208208 [
209- Argument ( DefaultLiteralExpression ) ,
210209 Argument ( IdentifierName ( "name" ) ) ,
211210 Argument ( DefaultLiteralExpression ) ,
211+ Argument ( DefaultLiteralExpression ) ,
212212 ] ) ) ) ) ) ) ) ;
213213
214214 // [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(defaultValue))]
215215 // public static object? GetObject(string name, object? defaultValue)
216216 // {
217- // return GetObject(default, name , defaultValue);
217+ // return GetObject(name, default , defaultValue);
218218 // }
219219 yield return MethodDeclaration ( NullableObjectType , Identifier ( "GetObject" ) )
220220 . WithAttributeLists ( SingletonList (
@@ -229,21 +229,21 @@ private static IEnumerable<MemberDeclarationSyntax> GenerateSharedMemberDeclarat
229229 ReturnStatement ( InvocationExpression ( IdentifierName ( "GetObject" ) )
230230 . WithArgumentList ( ArgumentList ( SeparatedList (
231231 [
232- Argument ( DefaultLiteralExpression ) ,
233232 Argument ( IdentifierName ( "name" ) ) ,
233+ Argument ( DefaultLiteralExpression ) ,
234234 Argument ( IdentifierName ( "defaultValue" ) ) ,
235235 ] ) ) ) ) ) ) ) ;
236236
237- // public static global::System.IO.Stream? GetStream(global::System.Globalization.CultureInfo? culture, string name )
237+ // public static global::System.IO.Stream? GetStream(string name, global::System.Globalization.CultureInfo? culture)
238238 // {
239239 // return ResourceManager.GetStream(name, culture ?? Culture);
240240 // }
241241 yield return MethodDeclaration ( NullableType ( TypeOfSystemIOStream ) , Identifier ( "GetStream" ) )
242242 . WithModifiers ( PublicStaticTokenList )
243243 . WithParameterList ( ParameterList ( SeparatedList (
244244 [
245- Parameter ( NullableType ( TypeOfSystemGlobalizationCultureInfo ) , Identifier ( "culture " ) ) ,
246- Parameter ( StringType , Identifier ( "name " ) )
245+ Parameter ( StringType , Identifier ( "name " ) ) ,
246+ Parameter ( NullableType ( TypeOfSystemGlobalizationCultureInfo ) , Identifier ( "culture " ) )
247247 ] ) ) )
248248 . WithBody ( Block ( SingletonList (
249249 ReturnStatement ( InvocationExpression ( SimpleMemberAccessExpression (
@@ -257,7 +257,7 @@ private static IEnumerable<MemberDeclarationSyntax> GenerateSharedMemberDeclarat
257257
258258 // public static global::System.IO.Stream? GetStream(string name)
259259 // {
260- // return GetStream(default, name );
260+ // return GetStream(name, default );
261261 // }
262262 yield return MethodDeclaration ( NullableType ( TypeOfSystemIOStream ) , Identifier ( "GetStream" ) )
263263 . WithModifiers ( PublicStaticTokenList )
@@ -267,11 +267,11 @@ private static IEnumerable<MemberDeclarationSyntax> GenerateSharedMemberDeclarat
267267 ReturnStatement ( InvocationExpression ( IdentifierName ( "GetStream" ) )
268268 . WithArgumentList ( ArgumentList ( SeparatedList (
269269 [
270- Argument ( DefaultLiteralExpression ) ,
271270 Argument ( IdentifierName ( "name" ) ) ,
271+ Argument ( DefaultLiteralExpression ) ,
272272 ] ) ) ) ) ) ) ) ;
273273
274- // public static string? GetString(global::System.Globalization.CultureInfo? culture, string name , params object?[]? args)
274+ // public static string? GetString(string name, global::System.Globalization.CultureInfo? culture, params object?[]? args)
275275 // {
276276 // culture ??= Culture;
277277 // string? str = ResourceManager.GetString(name, culture);
@@ -291,8 +291,8 @@ private static IEnumerable<MemberDeclarationSyntax> GenerateSharedMemberDeclarat
291291 . WithModifiers ( PublicStaticTokenList )
292292 . WithParameterList ( ParameterList ( SeparatedList (
293293 [
294- Parameter ( NullableType ( TypeOfSystemGlobalizationCultureInfo ) , Identifier ( "culture" ) ) ,
295294 Parameter ( StringType , Identifier ( "name" ) ) ,
295+ Parameter ( NullableType ( TypeOfSystemGlobalizationCultureInfo ) , Identifier ( "culture" ) ) ,
296296 NullableParamsArrayOfNullableObjectTypeParameter ( "args" )
297297 ] ) ) )
298298 . WithBody ( Block ( List < StatementSyntax > (
@@ -330,29 +330,9 @@ private static IEnumerable<MemberDeclarationSyntax> GenerateSharedMemberDeclarat
330330 ] ) ) ) )
331331 ] ) ) ) ;
332332
333- // public static string? GetString(global::System.Globalization.CultureInfo? culture, string name)
334- // {
335- // return GetString(culture, name, default);
336- // }
337- yield return MethodDeclaration ( NullableStringType , Identifier ( "GetString" ) )
338- . WithModifiers ( PublicStaticTokenList )
339- . WithParameterList ( ParameterList ( SeparatedList (
340- [
341- Parameter ( NullableType ( TypeOfSystemGlobalizationCultureInfo ) , Identifier ( "culture" ) ) ,
342- Parameter ( StringType , Identifier ( "name" ) )
343- ] ) ) )
344- . WithBody ( Block ( SingletonList (
345- ReturnStatement ( InvocationExpression ( IdentifierName ( "GetString" ) )
346- . WithArgumentList ( ArgumentList ( SeparatedList (
347- [
348- Argument ( IdentifierName ( "culture" ) ) ,
349- Argument ( IdentifierName ( "name" ) ) ,
350- Argument ( DefaultLiteralExpression ) ,
351- ] ) ) ) ) ) ) ) ;
352-
353333 // public static string? GetString(string name, params object?[]? args)
354334 // {
355- // return GetString(null, name , args);
335+ // return GetString(name, null , args);
356336 // }
357337 yield return MethodDeclaration ( NullableStringType , Identifier ( "GetString" ) )
358338 . WithModifiers ( PublicStaticTokenList )
@@ -365,147 +345,50 @@ private static IEnumerable<MemberDeclarationSyntax> GenerateSharedMemberDeclarat
365345 ReturnStatement ( InvocationExpression ( IdentifierName ( "GetString" ) )
366346 . WithArgumentList ( ArgumentList ( SeparatedList (
367347 [
368- Argument ( DefaultLiteralExpression ) ,
369348 Argument ( IdentifierName ( "name" ) ) ,
349+ Argument ( DefaultLiteralExpression ) ,
370350 Argument ( IdentifierName ( "args" ) )
371351 ] ) ) ) ) ) ) ) ;
372352
373- // [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(defaultValue))]
374- // public static string? GetStringOrDefault(global::System.Globalization.CultureInfo? culture, string name, string? defaultValue, params object?[]? args)
375- // {
376- // culture ??= Culture;
377- // string? str = ResourceManager.GetString(name, culture) ?? defaultValue;
378- // if (str is null)
379- // {
380- // return null;
381- // }
382- //
383- // if (args is null)
384- // {
385- // return str;
386- // }
387- //
388- // return string.Format(culture, str, args);
389- // }
390- yield return MethodDeclaration ( NullableStringType , Identifier ( "GetStringOrDefault" ) )
391- . WithAttributeLists ( SingletonList (
392- ReturnNotNullIfNotNullAttributeList ( "defaultValue" ) ) )
393- . WithModifiers ( PublicStaticTokenList )
394- . WithParameterList ( ParameterList ( SeparatedList (
395- [
396- Parameter ( NullableType ( TypeOfSystemGlobalizationCultureInfo ) , Identifier ( "culture" ) ) ,
397- Parameter ( StringType , Identifier ( "name" ) ) ,
398- Parameter ( NullableStringType , Identifier ( "defaultValue" ) ) ,
399- NullableParamsArrayOfNullableObjectTypeParameter ( "args" )
400- ] ) ) )
401- . WithBody ( Block ( List < StatementSyntax > (
402- [
403- ExpressionStatement ( CoalesceAssignmentExpression (
404- IdentifierName ( "culture" ) ,
405- IdentifierName ( "Culture" ) ) ) ,
406- LocalDeclarationStatement ( VariableDeclaration ( NullableStringType )
407- . WithVariables ( SingletonSeparatedList (
408- VariableDeclarator ( Identifier ( "str" ) )
409- . WithInitializer ( EqualsValueClause ( CoalesceExpression (
410- InvocationExpression ( SimpleMemberAccessExpression (
411- IdentifierName ( "ResourceManager" ) ,
412- IdentifierName ( "GetString" ) ) )
413- . WithArgumentList ( ArgumentList ( SeparatedList (
414- [
415- Argument ( IdentifierName ( "name" ) ) ,
416- Argument ( IdentifierName ( "culture" ) ) ,
417- ] ) ) ) ,
418- IdentifierName ( "defaultValue" ) ) ) ) ) ) ) ,
419- IfStatement (
420- IsPatternExpression ( IdentifierName ( "str" ) , ConstantPattern ( NullLiteralExpression ) ) ,
421- Block ( SingletonList ( ReturnStatement ( DefaultLiteralExpression ) ) ) ) ,
422- IfStatement (
423- IsPatternExpression ( IdentifierName ( "args" ) , ConstantPattern ( NullLiteralExpression ) ) ,
424- Block ( SingletonList ( ReturnStatement ( IdentifierName ( "str" ) ) ) ) ) ,
425- ReturnStatement (
426- InvocationExpression ( SimpleMemberAccessExpression (
427- StringType ,
428- IdentifierName ( "Format" ) ) )
429- . WithArgumentList ( ArgumentList ( SeparatedList (
430- [
431- Argument ( IdentifierName ( "culture" ) ) ,
432- Argument ( IdentifierName ( "str" ) ) ,
433- Argument ( IdentifierName ( "args" ) )
434- ] ) ) ) )
435- ] ) ) ) ;
436-
437- // [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(defaultValue))]
438- // public static string? GetStringOrDefault(global::System.Globalization.CultureInfo? culture, string name, string? defaultValue)
439- // {
440- // return GetStringOrDefault(culture, name, defaultValue, default);
441- // }
442- yield return MethodDeclaration ( NullableStringType , Identifier ( "GetStringOrDefault" ) )
443- . WithAttributeLists ( SingletonList (
444- ReturnNotNullIfNotNullAttributeList ( "defaultValue" ) ) )
445- . WithModifiers ( PublicStaticTokenList )
446- . WithParameterList ( ParameterList ( SeparatedList (
447- [
448- Parameter ( NullableType ( TypeOfSystemGlobalizationCultureInfo ) , Identifier ( "culture" ) ) ,
449- Parameter ( StringType , Identifier ( "name" ) ) ,
450- Parameter ( NullableStringType , Identifier ( "defaultValue" ) )
451- ] ) ) )
452- . WithBody ( Block ( SingletonList (
453- ReturnStatement ( InvocationExpression ( IdentifierName ( "GetStringOrDefault" ) )
454- . WithArgumentList ( ArgumentList ( SeparatedList (
455- [
456- Argument ( IdentifierName ( "culture" ) ) ,
457- Argument ( IdentifierName ( "name" ) ) ,
458- Argument ( IdentifierName ( "defaultValue" ) ) ,
459- Argument ( DefaultLiteralExpression )
460- ] ) ) ) ) ) ) ) ;
461-
462- // [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(defaultValue))]
463- // public static string? GetStringOrDefault(string name, string? defaultValue, params object?[]? args)
353+ // public static string? GetString(string name, global::System.Globalization.CultureInfo? culture)
464354 // {
465- // return GetStringOrDefault(null, name, defaultValue, args );
355+ // return ResourceManager.GetString( name, culture ?? Culture );
466356 // }
467- yield return MethodDeclaration ( NullableStringType , Identifier ( "GetStringOrDefault" ) )
468- . WithAttributeLists ( SingletonList (
469- ReturnNotNullIfNotNullAttributeList ( "defaultValue" ) ) )
357+ yield return MethodDeclaration ( NullableStringType , Identifier ( "GetString" ) )
470358 . WithModifiers ( PublicStaticTokenList )
471359 . WithParameterList ( ParameterList ( SeparatedList (
472360 [
473361 Parameter ( StringType , Identifier ( "name" ) ) ,
474- Parameter ( NullableStringType , Identifier ( "defaultValue" ) ) ,
475- NullableParamsArrayOfNullableObjectTypeParameter ( "args" )
362+ Parameter ( NullableType ( TypeOfSystemGlobalizationCultureInfo ) , Identifier ( "culture" ) )
476363 ] ) ) )
477364 . WithBody ( Block ( SingletonList (
478- ReturnStatement ( InvocationExpression ( IdentifierName ( "GetStringOrDefault" ) )
365+ ReturnStatement ( InvocationExpression ( SimpleMemberAccessExpression (
366+ IdentifierName ( "ResourceManager" ) ,
367+ IdentifierName ( "GetString" ) ) )
479368 . WithArgumentList ( ArgumentList ( SeparatedList (
480369 [
481- Argument ( DefaultLiteralExpression ) ,
482370 Argument ( IdentifierName ( "name" ) ) ,
483- Argument ( IdentifierName ( "defaultValue" ) ) ,
484- Argument ( IdentifierName ( "args" ) )
371+ Argument ( CoalesceExpression (
372+ IdentifierName ( "culture" ) ,
373+ IdentifierName ( "Culture" ) ) ) ,
485374 ] ) ) ) ) ) ) ) ;
486375
487- // [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(defaultValue))]
488- // public static string? GetStringOrDefault(string name, string? defaultValue)
376+ // public static string? GetString(string name)
489377 // {
490- // return GetStringOrDefault(null, name, defaultValue, null );
378+ // return ResourceManager.GetString( name, Culture );
491379 // }
492- yield return MethodDeclaration ( NullableStringType , Identifier ( "GetStringOrDefault" ) )
493- . WithAttributeLists ( SingletonList (
494- ReturnNotNullIfNotNullAttributeList ( "defaultValue" ) ) )
380+ yield return MethodDeclaration ( NullableStringType , Identifier ( "GetString" ) )
495381 . WithModifiers ( PublicStaticTokenList )
496- . WithParameterList ( ParameterList ( SeparatedList (
497- [
498- Parameter ( StringType , Identifier ( "name" ) ) ,
499- Parameter ( NullableStringType , Identifier ( "defaultValue" ) )
500- ] ) ) )
382+ . WithParameterList ( ParameterList ( SingletonSeparatedList (
383+ Parameter ( StringType , Identifier ( "name" ) ) ) ) )
501384 . WithBody ( Block ( SingletonList (
502- ReturnStatement ( InvocationExpression ( IdentifierName ( "GetStringOrDefault" ) )
385+ ReturnStatement ( InvocationExpression ( SimpleMemberAccessExpression (
386+ IdentifierName ( "ResourceManager" ) ,
387+ IdentifierName ( "GetString" ) ) )
503388 . WithArgumentList ( ArgumentList ( SeparatedList (
504389 [
505- Argument ( DefaultLiteralExpression ) ,
506390 Argument ( IdentifierName ( "name" ) ) ,
507- Argument ( IdentifierName ( "defaultValue" ) ) ,
508- Argument ( DefaultLiteralExpression )
391+ Argument ( IdentifierName ( "Culture" ) ) ,
509392 ] ) ) ) ) ) ) ) ;
510393 }
511394
0 commit comments