From c118a24cbfaf529c0a82cff3e5b00ae518bc8726 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 27 Sep 2017 22:27:22 +0200 Subject: [PATCH] Use Humanizer in GenerateForeachVariableName --- .../ICSharpCode.Decompiler.csproj | 1 + .../IL/Transforms/AssignVariableNames.cs | 19 ++++++------------- ILSpy/ILSpy.csproj | 1 + 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index c1edc9a5d..387d453b5 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -47,6 +47,7 @@ + diff --git a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs index d314e7ec0..4bd62a7f1 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Humanizer; using ICSharpCode.Decompiler.IL; using ICSharpCode.Decompiler.Semantics; using ICSharpCode.Decompiler.TypeSystem; @@ -432,19 +433,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms private static bool IsPlural(string baseName, ref string proposedName) { - if (baseName.EndsWith("ies", StringComparison.OrdinalIgnoreCase) && baseName.Length > 3) { - proposedName = baseName.Remove(baseName.Length - 3) + "y"; - return true; - } - if (baseName.EndsWith("es", StringComparison.OrdinalIgnoreCase) && baseName.Length > 2) { - proposedName = baseName.Remove(baseName.Length - 2); - return true; - } - if (baseName.EndsWith("s", StringComparison.OrdinalIgnoreCase) && baseName.Length > 1) { - proposedName = baseName.Remove(baseName.Length - 1); - return true; - } - return false; + var newName = baseName.Singularize(inputIsKnownToBePlural: false); + if (newName == baseName) + return false; + proposedName = newName; + return true; } } } diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index c164d93eb..3c2d99a63 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -398,5 +398,6 @@ + \ No newline at end of file