Browse Source

Fix references to nested classes within generic types. Closes #60.

pull/70/head
Daniel Grunwald 15 years ago
parent
commit
2af007d34c
  1. 28
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 6
      ICSharpCode.Decompiler/Tests/Generics.cs

28
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -260,10 +260,12 @@ namespace Decompiler
}; };
} }
AstType baseType = ConvertType(gType.ElementType, typeAttributes, ref typeIndex); AstType baseType = ConvertType(gType.ElementType, typeAttributes, ref typeIndex);
List<AstType> typeArguments = new List<AstType>();
foreach (var typeArgument in gType.GenericArguments) { foreach (var typeArgument in gType.GenericArguments) {
typeIndex++; typeIndex++;
baseType.AddChild(ConvertType(typeArgument, typeAttributes, ref typeIndex), AstType.Roles.TypeArgument); typeArguments.Add(ConvertType(typeArgument, typeAttributes, ref typeIndex));
} }
ApplyTypeArgumentsTo(baseType, typeArguments);
return baseType; return baseType;
} else if (type is GenericParameter) { } else if (type is GenericParameter) {
return new SimpleType(type.Name); return new SimpleType(type.Name);
@ -334,6 +336,30 @@ namespace Decompiler
} }
} }
static void ApplyTypeArgumentsTo(AstType baseType, List<AstType> typeArguments)
{
SimpleType st = baseType as SimpleType;
if (st != null) {
st.TypeArguments.AddRange(typeArguments);
}
MemberType mt = baseType as MemberType;
if (mt != null) {
TypeReference type = mt.Annotation<TypeReference>();
if (type != null) {
int typeParameterCount;
ICSharpCode.NRefactory.TypeSystem.ReflectionHelper.SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount);
if (typeParameterCount > typeArguments.Count)
typeParameterCount = typeArguments.Count;
mt.TypeArguments.AddRange(typeArguments.GetRange(typeArguments.Count - typeParameterCount, typeParameterCount));
typeArguments.RemoveRange(typeArguments.Count - typeParameterCount, typeParameterCount);
if (typeArguments.Count > 0)
ApplyTypeArgumentsTo(mt.Target, typeArguments);
} else {
mt.TypeArguments.AddRange(typeArguments);
}
}
}
const string DynamicAttributeFullName = "System.Runtime.CompilerServices.DynamicAttribute"; const string DynamicAttributeFullName = "System.Runtime.CompilerServices.DynamicAttribute";
static bool HasDynamicAttribute(ICustomAttributeProvider attributeProvider, int typeIndex) static bool HasDynamicAttribute(ICustomAttributeProvider attributeProvider, int typeIndex)

6
ICSharpCode.Decompiler/Tests/Generics.cs

@ -2,6 +2,7 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt) // This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System; using System;
using System.Collections.Generic;
public static class Generics public static class Generics
{ {
@ -31,4 +32,9 @@ public static class Generics
public static void MethodWithConstraint<T, S>() where T : class, S where S : ICloneable, new() public static void MethodWithConstraint<T, S>() where T : class, S where S : ICloneable, new()
{ {
} }
public static Dictionary<string, string>.KeyCollection.Enumerator GetEnumerator(Dictionary<string, string> d)
{
return d.Keys.GetEnumerator();
}
} }

Loading…
Cancel
Save