Browse Source

Output type parameters on type and method declarations. Closes #19.

pull/37/head
Daniel Grunwald 15 years ago
parent
commit
5b8600192e
  1. 25
      ICSharpCode.Decompiler/Ast/AstBuilder.cs

25
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -9,6 +9,7 @@ using ICSharpCode.NRefactory.CSharp; @@ -9,6 +9,7 @@ using ICSharpCode.NRefactory.CSharp;
using Mono.Cecil;
using Mono.Cecil.Cil;
using ClassType = ICSharpCode.NRefactory.TypeSystem.ClassType;
using VarianceModifier = ICSharpCode.NRefactory.TypeSystem.VarianceModifier;
namespace Decompiler
{
@ -141,6 +142,9 @@ namespace Decompiler @@ -141,6 +142,9 @@ namespace Decompiler
astType.ClassType = ClassType.Class;
}
astType.TypeParameters.AddRange(MakeTypeParameters(typeDef.GenericParameters));
astType.Constraints.AddRange(MakeConstraints(typeDef.GenericParameters));
// Nested types
foreach(TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
if (MemberIsHidden(nestedTypeDef))
@ -439,16 +443,33 @@ namespace Decompiler @@ -439,16 +443,33 @@ namespace Decompiler
{
MethodDeclaration astMethod = new MethodDeclaration();
astMethod.AddAnnotation(methodDef);
astMethod.Name = methodDef.Name;
astMethod.ReturnType = ConvertType(methodDef.ReturnType, methodDef.MethodReturnType);
astMethod.Name = methodDef.Name;
astMethod.TypeParameters.AddRange(MakeTypeParameters(methodDef.GenericParameters));
astMethod.Parameters.AddRange(MakeParameters(methodDef.Parameters));
astMethod.Constraints.AddRange(MakeConstraints(methodDef.GenericParameters));
if (!methodDef.DeclaringType.IsInterface) {
astMethod.Modifiers = ConvertModifiers(methodDef);
astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context);
}
return astMethod;
}
IEnumerable<TypeParameterDeclaration> MakeTypeParameters(IEnumerable<GenericParameter> genericParameters)
{
return genericParameters.Select(
gp => new TypeParameterDeclaration {
Name = gp.Name,
Variance = gp.IsContravariant ? VarianceModifier.Contravariant : gp.IsCovariant ? VarianceModifier.Covariant : VarianceModifier.Invariant
});
}
IEnumerable<Constraint> MakeConstraints(IEnumerable<GenericParameter> genericParameters)
{
// TODO
return Enumerable.Empty<Constraint>();
}
ConstructorDeclaration CreateConstructor(MethodDefinition methodDef)
{
ConstructorDeclaration astMethod = new ConstructorDeclaration();

Loading…
Cancel
Save