diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index bd9ecd13e6..81a2b328bc 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -30,7 +30,6 @@ using ICSharpCode.Decompiler.CSharp.OutputVisitor; using ICSharpCode.Decompiler.CSharp.Resolver; using ICSharpCode.Decompiler.CSharp.Syntax; -using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; using ICSharpCode.Decompiler.CSharp.Transforms; using ICSharpCode.Decompiler.DebugInfo; using ICSharpCode.Decompiler.Disassembler; @@ -1270,9 +1269,9 @@ void FixParameterNames(EntityDeclaration entity) int i = 0; foreach (var parameter in entity.GetChildrenByRole(Roles.Parameter)) { - if (string.IsNullOrEmpty(parameter.Name) && !parameter.Type.IsArgList()) + if (string.IsNullOrWhiteSpace(parameter.Name) && !parameter.Type.IsArgList()) { - // needs to be consistent with logic in ILReader.CreateILVarable(ParameterDefinition) + // needs to be consistent with logic in ILReader.CreateILVarable parameter.Name = "P_" + i; } i++; diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index d256cf6259..d0f4c056c0 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -26,6 +26,7 @@ using ICSharpCode.Decompiler.CSharp.Resolver; using ICSharpCode.Decompiler.CSharp.Syntax; using ICSharpCode.Decompiler.IL; +using ICSharpCode.Decompiler.IL.Transforms; using ICSharpCode.Decompiler.Semantics; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem.Implementation; @@ -781,7 +782,7 @@ private ArgumentList BuildArgumentList(ExpectedTargetDetails expectedTargetDetai argumentNames = new string[method.Parameters.Count]; } parameter = method.Parameters[argumentToParameterMap[i]]; - if (argumentNames != null) + if (argumentNames != null && AssignVariableNames.IsValidName(parameter.Name)) { argumentNames[arguments.Count] = parameter.Name; } diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index 10046abaff..6bf9b5b5e4 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -19,7 +19,6 @@ #nullable enable using System; -using System.Collections; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; @@ -334,7 +333,7 @@ ILVariable CreateILVariable(int index, IType parameterType, string name) Debug.Assert(ilVar.StoreCount == 1); // count the initial store when the method is called with an argument if (index < 0) ilVar.Name = "this"; - else if (string.IsNullOrEmpty(name)) + else if (string.IsNullOrWhiteSpace(name)) ilVar.Name = "P_" + index; else ilVar.Name = name; diff --git a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs index 2fd3f7782d..2832e9e25a 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs @@ -202,7 +202,9 @@ void PerformAssignment(ILFunction function) { switch (v.Kind) { - case VariableKind.Parameter: // ignore + case VariableKind.Parameter: + // Parameter names are handled in ILReader.CreateILVariable + // and CSharpDecompiler.FixParameterNames break; case VariableKind.InitializerTarget: // keep generated names AddExistingName(reservedVariableNames, v.Name); @@ -326,9 +328,9 @@ bool ConflictWithLocal(ILVariable v) return false; } - static bool IsValidName(string varName) + internal static bool IsValidName(string varName) { - if (string.IsNullOrEmpty(varName)) + if (string.IsNullOrWhiteSpace(varName)) return false; if (!(char.IsLetter(varName[0]) || varName[0] == '_')) return false;