Skip to content

Improve C# Code Generator to use Roslyn SyntaxFactory instead of basic string concatenation #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ReswPlus.Shared/ResourceParser/FormatTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public FunctionFormatTagParameter(ParameterType type, string name, ParameterType

public sealed class FunctionFormatTagParametersInfo
{
public List<IFormatTagParameter> Parameters { get; set; } = new();
public List<IFormatTagParameter> Parameters { get; set; } = [];
public FunctionFormatTagParameter? PluralizationParameter { get; set; }
public FunctionFormatTagParameter? VariantParameter { get; set; }
}
Expand Down
2 changes: 1 addition & 1 deletion src/ReswPlus.Shared/ResourceParser/ReswInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public sealed class ReswInfo

public ReswInfo()
{
Items = new();
Items = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ protected Localization(string key, string summary)
/// <summary>
/// Gets or sets the list of format tag parameters.
/// </summary>
public List<IFormatTagParameter> Parameters { get; set; } = new();
public List<IFormatTagParameter> Parameters { get; set; } = [];

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

/// <summary>
/// Gets or sets the summary for the localization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public StronglyTypedClass(bool isAdvanced, string[] namespaces, string resoureFi
ResoureFile = resoureFile;
ClassName = className;
AppType = appType;
Items = new();
Items = [];
}

public bool IsAdvanced { get; }
Expand Down
156 changes: 63 additions & 93 deletions src/ReswPlus.SourceGenerator/ClassGenerators/PluralFormsRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ public PluralForm(string id, string[] languages)
/// <summary>
/// A static collection of predefined plural forms and their associated languages.
/// </summary>
private static readonly PluralForm[] PluralForms = new PluralForm[]
{
private static readonly PluralForm[] PluralForms =
[
new PluralForm(
"IntOneOrZero",
new[]
{
[
"ak", // Akan
"bh", // Bihari
"guw", // Gun
Expand All @@ -37,12 +36,11 @@ public PluralForm(string id, string[] languages)
"pa", // Punjabi
"ti", // Tigrinya
"wa" // Walloon
}
]
),
new PluralForm(
"ZeroToOne",
new[]
{
[
"am", // Amharic
"bn", // Bengali
"ff", // Fulah
Expand All @@ -52,21 +50,19 @@ public PluralForm(string id, string[] languages)
"mr", // Marathi
"fa", // Persian
"zu" // Zulu
}
]
),
new PluralForm(
"ZeroToTwoExcluded",
new[]
{
[
"hy", // Armenian
"fr", // French
"kab" // Kabyle
}
]
),
new PluralForm(
"OnlyOne",
new[]
{
[
"af", // Afrikaans
"sq", // Albanian
"ast", // Asturian
Expand Down Expand Up @@ -166,138 +162,120 @@ public PluralForm(string id, string[] languages)
"xh", // Xhosa
"yi", // Yiddish
"ji" // Jiddish
}
]
),
new PluralForm(
"Sinhala",
new[]
{
[
"si" // Sinhala
}
]
),
new PluralForm(
"Latvian",
new[]
{
[
"lv", // Latvian
"prg" // Prussian
}
]
),
new PluralForm(
"Irish",
new[]
{
[
"ga" // Irish
}
]
),
new PluralForm(
"Romanian",
new[]
{
[
"ro", // Romanian
"mo" // Moldavian
}
]
),
new PluralForm(
"Lithuanian",
new[]
{
[
"lt" // Lithuanian
}
]
),
new PluralForm(
"Slavic",
new[]
{
[
"ru", // Russian
"uk", // Ukrainian
"be" // Belarusian
}
]
),
new PluralForm(
"Czech",
new[]
{
[
"cs", // Czech
"sk" // Slovak
}
]
),
new PluralForm(
"Polish",
new[]
{
[
"pl" // Polish
}
]
),
new PluralForm(
"Slovenian",
new[]
{
[
"sl" // Slovenian
}
]
),
new PluralForm(
"Arabic",
new[]
{
[
"ar" // Arabic
}
]
),
new PluralForm(
"Hebrew",
new[]
{
[
"he", // Hebrew
"iw" // (old code for Hebrew)
}
]
),
new PluralForm(
"Filipino",
new[]
{
[
"fil", // Filipino
"tl" // Tagalog
}
]
),
new PluralForm(
"Macedonian",
new[]
{
[
"mk" // Macedonian
}
]
),
new PluralForm(
"Breizh",
new[]
{
[
"br" // Breton
}
]
),
new PluralForm(
"CentralAtlasTamazight",
new[]
{
[
"tzm" // Central Atlas Tamazight
}
]
),
new PluralForm(
"OneOrZero",
new[]
{
[
"ksh" // Colognian
}
]
),
new PluralForm(
"OneOrZeroToOneExcluded",
new[]
{
[
"lag" // Langi
}
]
),
new PluralForm(
"OneOrTwo",
new[]
{
[
"kw", // Cornish
"smn", // Inari Sami
"iu", // Inuktitut
Expand All @@ -307,68 +285,60 @@ public PluralForm(string id, string[] languages)
"smi", // Other Sami languages
"sms", // Skolt Sami
"sma" // Southern Sami
}
]
),
new PluralForm(
"Croat",
new[]
{
[
"bs", // Bosnian
"hr", // Croatian
"sr", // Serbian
"sh" // Serbo-Croatian
}
]
),
new PluralForm(
"Tachelhit",
new[]
{
[
"shi" // Tachelhit
}
]
),
new PluralForm(
"Icelandic",
new[]
{
[
"is" // Icelandic
}
]
),
new PluralForm(
"Manx",
new[]
{
[
"gv" // Manx
}
]
),
new PluralForm(
"ScottishGaelic",
new[]
{
[
"gd" // Scottish Gaelic
}
]
),
new PluralForm(
"Maltese",
new[]
{
[
"mt" // Maltese
}
]
),
new PluralForm(
"Welsh",
new[]
{
[
"cy" // Welsh
}
]
),
new PluralForm(
"Danish",
new[]
{
[
"da" // Danish
}
]
)
};
];

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