diff --git a/ICSharpCode.Decompiler/Ast/AstBuilder.cs b/ICSharpCode.Decompiler/Ast/AstBuilder.cs index 434f91888..f7f63a15d 100644 --- a/ICSharpCode.Decompiler/Ast/AstBuilder.cs +++ b/ICSharpCode.Decompiler/Ast/AstBuilder.cs @@ -513,8 +513,23 @@ namespace Decompiler IEnumerable MakeConstraints(IEnumerable genericParameters) { - // TODO - return Enumerable.Empty(); + foreach (var gp in genericParameters) { + Constraint c = new Constraint(); + c.TypeParameter = CleanName(gp.Name); + // class/struct must be first + if (gp.HasReferenceTypeConstraint) + c.BaseTypes.Add(new PrimitiveType("class")); + if (gp.HasNotNullableValueTypeConstraint) + c.BaseTypes.Add(new PrimitiveType("struct")); + + foreach (var constraintType in gp.Constraints) + c.BaseTypes.Add(ConvertType(constraintType)); + + if (gp.HasDefaultConstructorConstraint) + c.BaseTypes.Add(new PrimitiveType("new")); // new() must be last + if (c.BaseTypes.Any()) + yield return c; + } } ConstructorDeclaration CreateConstructor(MethodDefinition methodDef) diff --git a/ICSharpCode.Decompiler/Tests/Generics.cs b/ICSharpCode.Decompiler/Tests/Generics.cs index 636eb708c..d0b6cf240 100644 --- a/ICSharpCode.Decompiler/Tests/Generics.cs +++ b/ICSharpCode.Decompiler/Tests/Generics.cs @@ -27,4 +27,8 @@ public static class Generics } } } + + public static void MethodWithConstraint() where T : class, S where S : ICloneable, new() + { + } }