Browse Source

Fix parameter names of methods and indexers if names are empty.

pull/728/head
Siegfried Pammer 9 years ago
parent
commit
acc65ecf5c
  1. 14
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 6
      ICSharpCode.Decompiler/CSharp/NRefactoryExtensions.cs

14
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -464,6 +464,18 @@ namespace ICSharpCode.Decompiler.CSharp @@ -464,6 +464,18 @@ namespace ICSharpCode.Decompiler.CSharp
}
#endregion
void FixParameterNames(EntityDeclaration entity)
{
int i = 0;
foreach (var parameter in entity.GetChildrenByRole(Roles.Parameter)) {
if (string.IsNullOrEmpty(parameter.Name) && !parameter.Type.IsArgList()) {
// needs to be consistent with logic in ILReader.CreateILVarable(ParameterDefinition)
parameter.Name = "P_" + i;
}
i++;
}
}
EntityDeclaration DoDecompile(ITypeDefinition typeDef, ITypeResolveContext decompilationContext)
{
Debug.Assert(decompilationContext.CurrentTypeDefinition == typeDef);
@ -534,6 +546,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -534,6 +546,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (method.IsExplicitInterfaceImplementation && lastDot >= 0) {
methodDecl.Name = method.Name.Substring(lastDot + 1);
}
FixParameterNames(methodDecl);
if (methodDefinition.HasBody) {
DecompileBody(methodDefinition, method, methodDecl, decompilationContext, typeSystemAstBuilder);
} else if (!method.IsAbstract && method.DeclaringType.Kind != TypeKind.Interface) {
@ -622,6 +635,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -622,6 +635,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (property.IsExplicitInterfaceImplementation && !property.IsIndexer) {
propertyDecl.Name = property.Name.Substring(lastDot + 1);
}
FixParameterNames(propertyDecl);
Accessor getter, setter;
if (propertyDecl is PropertyDeclaration) {
getter = ((PropertyDeclaration)propertyDecl).Getter;

6
ICSharpCode.Decompiler/CSharp/NRefactoryExtensions.cs

@ -84,5 +84,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -84,5 +84,11 @@ namespace ICSharpCode.Decompiler.CSharp
next = next.NextSibling;
return (Statement)next;
}
public static bool IsArgList(this AstType type)
{
var simpleType = type as SimpleType;
return simpleType != null && simpleType.Identifier == "__arglist";
}
}
}

Loading…
Cancel
Save