Skip to content

Commit 081400f

Browse files
committed
[SourceGen] Recognize property as Dictionary with "_DictKvp" prefix
1 parent 6f83ff1 commit 081400f

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

Hi3Helper.LocaleSourceGen/Hi3Helper.LocaleSourceGen.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Hi3Helper.SourceGen" Version="0.0.1" />
14+
<PackageReference Include="Hi3Helper.SourceGen" Version="0.0.3" />
1515
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.2.0" />
1616
</ItemGroup>
1717

Hi3Helper.SourceGen/Hi3Helper.SourceGen.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<Nullable>enable</Nullable>
1111
<IsAotCompatible>false</IsAotCompatible>
1212

13-
<Version>0.0.2</Version>
14-
<AssemblyVersion>0.0.2</AssemblyVersion>
13+
<Version>0.0.3</Version>
14+
<AssemblyVersion>0.0.3</AssemblyVersion>
1515
<DebugType>embedded</DebugType>
1616

1717
<!-- NuGet Packing -->

Hi3Helper.SourceGen/Locale/LocaleSourceGenerator.GetPropertyType.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public partial class LocaleSourceGenerator
1414
private const string DefaultRetTypeString = "string.Empty";
1515
private const string DefaultRetTypeDict = "[]";
1616

17+
private static readonly string ClassNameAsDictStringStringPrefix = "_DictKvp";
1718
private static readonly HashSet<string> ClassNamesAsDictStringString = [
1819
"_GameClientTitles",
1920
"_GameClientRegions",
@@ -34,7 +35,9 @@ private static void GetPropertyType(JsonProperty property, string classNamePrefi
3435
// Check for object types
3536
case JsonValueKind.Object:
3637
// If the property type is the language section itself, then return its own type instead.
37-
if (property.Name[0] == '_' && !ClassNamesAsDictStringString.Contains(property.Name))
38+
if (property.Name[0] == '_' &&
39+
!(ClassNamesAsDictStringString.Contains(property.Name) ||
40+
property.Name.StartsWith(ClassNameAsDictStringStringPrefix, StringComparison.OrdinalIgnoreCase)))
3841
{
3942
typeName = $"{classNamePrefix}{property.Name.Substring(1)}";
4043
defaultValueSyntax = "default";

0 commit comments

Comments
 (0)