Browse Source

Output constraints for generic methods.

pull/70/head
Daniel Grunwald 16 years ago
parent
commit
c24ec99ae0
  1. 19
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 4
      ICSharpCode.Decompiler/Tests/Generics.cs

19
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -513,8 +513,23 @@ namespace Decompiler @@ -513,8 +513,23 @@ namespace Decompiler
IEnumerable<Constraint> MakeConstraints(IEnumerable<GenericParameter> genericParameters)
{
// TODO
return Enumerable.Empty<Constraint>();
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)

4
ICSharpCode.Decompiler/Tests/Generics.cs

@ -27,4 +27,8 @@ public static class Generics @@ -27,4 +27,8 @@ public static class Generics
}
}
}
public static void MethodWithConstraint<T, S>() where T : class, S where S : ICloneable, new()
{
}
}

Loading…
Cancel
Save