Browse Source

Fix definition of nested classes in generic classes.

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

14
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -155,8 +155,11 @@ namespace Decompiler @@ -155,8 +155,11 @@ namespace Decompiler
astType.ClassType = ClassType.Class;
}
astType.TypeParameters.AddRange(MakeTypeParameters(typeDef.GenericParameters));
astType.Constraints.AddRange(MakeConstraints(typeDef.GenericParameters));
IEnumerable<GenericParameter> genericParameters = typeDef.GenericParameters;
if (typeDef.DeclaringType != null && typeDef.DeclaringType.HasGenericParameters)
genericParameters = genericParameters.Skip(typeDef.DeclaringType.GenericParameters.Count);
astType.TypeParameters.AddRange(MakeTypeParameters(genericParameters));
astType.Constraints.AddRange(MakeConstraints(genericParameters));
// Nested types
foreach(TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
@ -548,10 +551,13 @@ namespace Decompiler @@ -548,10 +551,13 @@ namespace Decompiler
if (gp.HasNotNullableValueTypeConstraint)
c.BaseTypes.Add(new PrimitiveType("struct"));
foreach (var constraintType in gp.Constraints)
foreach (var constraintType in gp.Constraints) {
if (gp.HasNotNullableValueTypeConstraint && constraintType.FullName == "System.ValueType")
continue;
c.BaseTypes.Add(ConvertType(constraintType));
}
if (gp.HasDefaultConstructorConstraint)
if (gp.HasDefaultConstructorConstraint && !gp.HasNotNullableValueTypeConstraint)
c.BaseTypes.Add(new PrimitiveType("new")); // new() must be last
if (c.BaseTypes.Any())
yield return c;

15
ICSharpCode.Decompiler/Tests/Generics.cs

@ -6,8 +6,14 @@ using System.Collections.Generic; @@ -6,8 +6,14 @@ using System.Collections.Generic;
public static class Generics
{
class MyArray<T>
public class MyArray<T>
{
public class NestedClass<Y>
{
public T Item1;
public Y Item2;
}
private T[] arr;
public MyArray(int capacity)
@ -33,8 +39,13 @@ public static class Generics @@ -33,8 +39,13 @@ public static class Generics
{
}
public static Dictionary<string, string>.KeyCollection.Enumerator GetEnumerator(Dictionary<string, string> d)
public static void MethodWithStructConstraint<T>() where T : struct
{
}
public static Dictionary<string, string>.KeyCollection.Enumerator GetEnumerator(Dictionary<string, string> d, MyArray<string>.NestedClass<int> nc)
{
// Tests references to inner classes in generic classes
return d.Keys.GetEnumerator();
}
}

Loading…
Cancel
Save