Skip to content

Commit e6dafb6

Browse files
authored
Improve C# Code Generator to use Roslyn SyntaxFactory instead of basic string concatenation (#43)
1 parent 326332d commit e6dafb6

File tree

10 files changed

+841
-505
lines changed

10 files changed

+841
-505
lines changed

src/ReswPlus.Shared/ResourceParser/FormatTag.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public FunctionFormatTagParameter(ParameterType type, string name, ParameterType
5656

5757
public sealed class FunctionFormatTagParametersInfo
5858
{
59-
public List<IFormatTagParameter> Parameters { get; set; } = new();
59+
public List<IFormatTagParameter> Parameters { get; set; } = [];
6060
public FunctionFormatTagParameter? PluralizationParameter { get; set; }
6161
public FunctionFormatTagParameter? VariantParameter { get; set; }
6262
}

src/ReswPlus.Shared/ResourceParser/ReswInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ public sealed class ReswInfo
88

99
public ReswInfo()
1010
{
11-
Items = new();
11+
Items = [];
1212
}
1313
}

src/ReswPlus.SourceGenerator/ClassGenerators/Models/Localization.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ protected Localization(string key, string summary)
2323
/// <summary>
2424
/// Gets or sets the list of format tag parameters.
2525
/// </summary>
26-
public List<IFormatTagParameter> Parameters { get; set; } = new();
26+
public List<IFormatTagParameter> Parameters { get; set; } = [];
2727

2828
/// <summary>
2929
/// Gets the list of extra function format tag parameters.
3030
/// </summary>
31-
public List<FunctionFormatTagParameter> ExtraParameters { get; } = new();
31+
public List<FunctionFormatTagParameter> ExtraParameters { get; } = [];
3232

3333
/// <summary>
3434
/// Gets or sets the summary for the localization.

src/ReswPlus.SourceGenerator/ClassGenerators/Models/StronglyTypedClass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public StronglyTypedClass(bool isAdvanced, string[] namespaces, string resoureFi
1111
ResoureFile = resoureFile;
1212
ClassName = className;
1313
AppType = appType;
14-
Items = new();
14+
Items = [];
1515
}
1616

1717
public bool IsAdvanced { get; }

src/ReswPlus.SourceGenerator/ClassGenerators/PluralFormsRetriever.cs

Lines changed: 63 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ public PluralForm(string id, string[] languages)
2222
/// <summary>
2323
/// A static collection of predefined plural forms and their associated languages.
2424
/// </summary>
25-
private static readonly PluralForm[] PluralForms = new PluralForm[]
26-
{
25+
private static readonly PluralForm[] PluralForms =
26+
[
2727
new PluralForm(
2828
"IntOneOrZero",
29-
new[]
30-
{
29+
[
3130
"ak", // Akan
3231
"bh", // Bihari
3332
"guw", // Gun
@@ -37,12 +36,11 @@ public PluralForm(string id, string[] languages)
3736
"pa", // Punjabi
3837
"ti", // Tigrinya
3938
"wa" // Walloon
40-
}
39+
]
4140
),
4241
new PluralForm(
4342
"ZeroToOne",
44-
new[]
45-
{
43+
[
4644
"am", // Amharic
4745
"bn", // Bengali
4846
"ff", // Fulah
@@ -52,21 +50,19 @@ public PluralForm(string id, string[] languages)
5250
"mr", // Marathi
5351
"fa", // Persian
5452
"zu" // Zulu
55-
}
53+
]
5654
),
5755
new PluralForm(
5856
"ZeroToTwoExcluded",
59-
new[]
60-
{
57+
[
6158
"hy", // Armenian
6259
"fr", // French
6360
"kab" // Kabyle
64-
}
61+
]
6562
),
6663
new PluralForm(
6764
"OnlyOne",
68-
new[]
69-
{
65+
[
7066
"af", // Afrikaans
7167
"sq", // Albanian
7268
"ast", // Asturian
@@ -166,138 +162,120 @@ public PluralForm(string id, string[] languages)
166162
"xh", // Xhosa
167163
"yi", // Yiddish
168164
"ji" // Jiddish
169-
}
165+
]
170166
),
171167
new PluralForm(
172168
"Sinhala",
173-
new[]
174-
{
169+
[
175170
"si" // Sinhala
176-
}
171+
]
177172
),
178173
new PluralForm(
179174
"Latvian",
180-
new[]
181-
{
175+
[
182176
"lv", // Latvian
183177
"prg" // Prussian
184-
}
178+
]
185179
),
186180
new PluralForm(
187181
"Irish",
188-
new[]
189-
{
182+
[
190183
"ga" // Irish
191-
}
184+
]
192185
),
193186
new PluralForm(
194187
"Romanian",
195-
new[]
196-
{
188+
[
197189
"ro", // Romanian
198190
"mo" // Moldavian
199-
}
191+
]
200192
),
201193
new PluralForm(
202194
"Lithuanian",
203-
new[]
204-
{
195+
[
205196
"lt" // Lithuanian
206-
}
197+
]
207198
),
208199
new PluralForm(
209200
"Slavic",
210-
new[]
211-
{
201+
[
212202
"ru", // Russian
213203
"uk", // Ukrainian
214204
"be" // Belarusian
215-
}
205+
]
216206
),
217207
new PluralForm(
218208
"Czech",
219-
new[]
220-
{
209+
[
221210
"cs", // Czech
222211
"sk" // Slovak
223-
}
212+
]
224213
),
225214
new PluralForm(
226215
"Polish",
227-
new[]
228-
{
216+
[
229217
"pl" // Polish
230-
}
218+
]
231219
),
232220
new PluralForm(
233221
"Slovenian",
234-
new[]
235-
{
222+
[
236223
"sl" // Slovenian
237-
}
224+
]
238225
),
239226
new PluralForm(
240227
"Arabic",
241-
new[]
242-
{
228+
[
243229
"ar" // Arabic
244-
}
230+
]
245231
),
246232
new PluralForm(
247233
"Hebrew",
248-
new[]
249-
{
234+
[
250235
"he", // Hebrew
251236
"iw" // (old code for Hebrew)
252-
}
237+
]
253238
),
254239
new PluralForm(
255240
"Filipino",
256-
new[]
257-
{
241+
[
258242
"fil", // Filipino
259243
"tl" // Tagalog
260-
}
244+
]
261245
),
262246
new PluralForm(
263247
"Macedonian",
264-
new[]
265-
{
248+
[
266249
"mk" // Macedonian
267-
}
250+
]
268251
),
269252
new PluralForm(
270253
"Breizh",
271-
new[]
272-
{
254+
[
273255
"br" // Breton
274-
}
256+
]
275257
),
276258
new PluralForm(
277259
"CentralAtlasTamazight",
278-
new[]
279-
{
260+
[
280261
"tzm" // Central Atlas Tamazight
281-
}
262+
]
282263
),
283264
new PluralForm(
284265
"OneOrZero",
285-
new[]
286-
{
266+
[
287267
"ksh" // Colognian
288-
}
268+
]
289269
),
290270
new PluralForm(
291271
"OneOrZeroToOneExcluded",
292-
new[]
293-
{
272+
[
294273
"lag" // Langi
295-
}
274+
]
296275
),
297276
new PluralForm(
298277
"OneOrTwo",
299-
new[]
300-
{
278+
[
301279
"kw", // Cornish
302280
"smn", // Inari Sami
303281
"iu", // Inuktitut
@@ -307,68 +285,60 @@ public PluralForm(string id, string[] languages)
307285
"smi", // Other Sami languages
308286
"sms", // Skolt Sami
309287
"sma" // Southern Sami
310-
}
288+
]
311289
),
312290
new PluralForm(
313291
"Croat",
314-
new[]
315-
{
292+
[
316293
"bs", // Bosnian
317294
"hr", // Croatian
318295
"sr", // Serbian
319296
"sh" // Serbo-Croatian
320-
}
297+
]
321298
),
322299
new PluralForm(
323300
"Tachelhit",
324-
new[]
325-
{
301+
[
326302
"shi" // Tachelhit
327-
}
303+
]
328304
),
329305
new PluralForm(
330306
"Icelandic",
331-
new[]
332-
{
307+
[
333308
"is" // Icelandic
334-
}
309+
]
335310
),
336311
new PluralForm(
337312
"Manx",
338-
new[]
339-
{
313+
[
340314
"gv" // Manx
341-
}
315+
]
342316
),
343317
new PluralForm(
344318
"ScottishGaelic",
345-
new[]
346-
{
319+
[
347320
"gd" // Scottish Gaelic
348-
}
321+
]
349322
),
350323
new PluralForm(
351324
"Maltese",
352-
new[]
353-
{
325+
[
354326
"mt" // Maltese
355-
}
327+
]
356328
),
357329
new PluralForm(
358330
"Welsh",
359-
new[]
360-
{
331+
[
361332
"cy" // Welsh
362-
}
333+
]
363334
),
364335
new PluralForm(
365336
"Danish",
366-
new[]
367-
{
337+
[
368338
"da" // Danish
369-
}
339+
]
370340
)
371-
};
341+
];
372342

373343
// Prebuild a dictionary that maps each language code to its plural form.
374344
private static readonly Dictionary<string, PluralForm> LanguageToPluralForm = BuildLanguageToPluralForm();

0 commit comments

Comments
 (0)