From ba282261944ac0f7e324de3d02c85197007cf051 Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Sun, 3 Nov 2024 19:16:03 +0800 Subject: [PATCH] Add summary for resx enum --- .../Resx/ResxGenerator.cs | 33 ++++++++----------- .../Snap.Hutao.SourceGeneration.csproj | 2 +- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/Snap.Hutao.SourceGeneration/Snap.Hutao.SourceGeneration/Resx/ResxGenerator.cs b/src/Snap.Hutao.SourceGeneration/Snap.Hutao.SourceGeneration/Resx/ResxGenerator.cs index 61ca2ca..b6ffb30 100644 --- a/src/Snap.Hutao.SourceGeneration/Snap.Hutao.SourceGeneration/Resx/ResxGenerator.cs +++ b/src/Snap.Hutao.SourceGeneration/Snap.Hutao.SourceGeneration/Resx/ResxGenerator.cs @@ -269,6 +269,13 @@ internal partial class {{className}} """); + StringBuilder enumBuilder = new($$""" + } + + internal enum {{className}}Name + { + """); + foreach (ResxEntry? entry in entries.OrderBy(e => e.Name, StringComparer.Ordinal)) { if (string.IsNullOrEmpty(entry.Name)) @@ -302,6 +309,12 @@ internal partial class {{className}} } """); + + enumBuilder.AppendLine($""" + /// {comment} + {ToCSharpNameIdentifier(entry.Name!)}, + + """); if (entry.Values.FirstOrDefault() is string value) { @@ -340,25 +353,7 @@ internal partial class {{className}} } } - sb.AppendLine($$""" - } - - internal enum {{className}}Name - { - """); - - foreach (ResxEntry entry in entries) - { - if (string.IsNullOrEmpty(entry.Name)) - { - continue; - } - - sb.AppendLine($$""" - {{ToCSharpNameIdentifier(entry.Name!)}}, - """); - } - + sb.AppendLine(enumBuilder.ToString()); sb.AppendLine("}"); return sb.ToString(); diff --git a/src/Snap.Hutao.SourceGeneration/Snap.Hutao.SourceGeneration/Snap.Hutao.SourceGeneration.csproj b/src/Snap.Hutao.SourceGeneration/Snap.Hutao.SourceGeneration/Snap.Hutao.SourceGeneration.csproj index 562630f..74019f8 100644 --- a/src/Snap.Hutao.SourceGeneration/Snap.Hutao.SourceGeneration/Snap.Hutao.SourceGeneration.csproj +++ b/src/Snap.Hutao.SourceGeneration/Snap.Hutao.SourceGeneration/Snap.Hutao.SourceGeneration.csproj @@ -32,7 +32,7 @@ Snap.Hutao.SourceGeneration - 1.1.27 + 1.1.28 DGP Studio false true