diff --git a/ICSharpCode.Decompiler/Ast/AstBuilder.cs b/ICSharpCode.Decompiler/Ast/AstBuilder.cs index f7f63a15d..3e2fd1ce3 100644 --- a/ICSharpCode.Decompiler/Ast/AstBuilder.cs +++ b/ICSharpCode.Decompiler/Ast/AstBuilder.cs @@ -260,10 +260,12 @@ namespace Decompiler }; } AstType baseType = ConvertType(gType.ElementType, typeAttributes, ref typeIndex); + List typeArguments = new List(); foreach (var typeArgument in gType.GenericArguments) { typeIndex++; - baseType.AddChild(ConvertType(typeArgument, typeAttributes, ref typeIndex), AstType.Roles.TypeArgument); + typeArguments.Add(ConvertType(typeArgument, typeAttributes, ref typeIndex)); } + ApplyTypeArgumentsTo(baseType, typeArguments); return baseType; } else if (type is GenericParameter) { return new SimpleType(type.Name); @@ -334,6 +336,30 @@ namespace Decompiler } } + static void ApplyTypeArgumentsTo(AstType baseType, List 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(); + 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"; static bool HasDynamicAttribute(ICustomAttributeProvider attributeProvider, int typeIndex) diff --git a/ICSharpCode.Decompiler/Tests/Generics.cs b/ICSharpCode.Decompiler/Tests/Generics.cs index d0b6cf240..3666d0d95 100644 --- a/ICSharpCode.Decompiler/Tests/Generics.cs +++ b/ICSharpCode.Decompiler/Tests/Generics.cs @@ -2,6 +2,7 @@ // This code is distributed under MIT X11 license (for details please see \doc\license.txt) using System; +using System.Collections.Generic; public static class Generics { @@ -31,4 +32,9 @@ public static class Generics public static void MethodWithConstraint() where T : class, S where S : ICloneable, new() { } + + public static Dictionary.KeyCollection.Enumerator GetEnumerator(Dictionary d) + { + return d.Keys.GetEnumerator(); + } }