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;
using Mono.Cecil; using Mono.Cecil;
using Mono.Cecil.Cil; using Mono.Cecil.Cil;
using ClassType = ICSharpCode.NRefactory.TypeSystem.ClassType; using ClassType = ICSharpCode.NRefactory.TypeSystem.ClassType;
using VarianceModifier = ICSharpCode.NRefactory.TypeSystem.VarianceModifier;
namespace Decompiler namespace Decompiler
{ {
@ -141,6 +142,9 @@ namespace Decompiler
astType.ClassType = ClassType.Class; astType.ClassType = ClassType.Class;
} }
astType.TypeParameters.AddRange(MakeTypeParameters(typeDef.GenericParameters));
astType.Constraints.AddRange(MakeConstraints(typeDef.GenericParameters));
// Nested types // Nested types
foreach(TypeDefinition nestedTypeDef in typeDef.NestedTypes) { foreach(TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
if (MemberIsHidden(nestedTypeDef)) if (MemberIsHidden(nestedTypeDef))
@ -439,16 +443,33 @@ namespace Decompiler
{ {
MethodDeclaration astMethod = new MethodDeclaration(); MethodDeclaration astMethod = new MethodDeclaration();
astMethod.AddAnnotation(methodDef); astMethod.AddAnnotation(methodDef);
astMethod.Name = methodDef.Name;
astMethod.ReturnType = ConvertType(methodDef.ReturnType, methodDef.MethodReturnType); astMethod.ReturnType = ConvertType(methodDef.ReturnType, methodDef.MethodReturnType);
astMethod.Name = methodDef.Name;
astMethod.TypeParameters.AddRange(MakeTypeParameters(methodDef.GenericParameters));
astMethod.Parameters.AddRange(MakeParameters(methodDef.Parameters)); astMethod.Parameters.AddRange(MakeParameters(methodDef.Parameters));
astMethod.Constraints.AddRange(MakeConstraints(methodDef.GenericParameters));
if (!methodDef.DeclaringType.IsInterface) { if (!methodDef.DeclaringType.IsInterface) {
astMethod.Modifiers = ConvertModifiers(methodDef); astMethod.Modifiers = ConvertModifiers(methodDef);
astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context); astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context);
} }
return astMethod; 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 CreateConstructor(MethodDefinition methodDef)
{ {
ConstructorDeclaration astMethod = new ConstructorDeclaration(); ConstructorDeclaration astMethod = new ConstructorDeclaration();

Loading…
Cancel
Save