Permalink
Browse files

Remove `n from generic class names.

  • Loading branch information...
1 parent 1607321 commit f648be9fb7423e49675af289cbf5b0915f7ace62 @dgrunwald dgrunwald committed Feb 24, 2011
Showing with 16 additions and 8 deletions.
  1. +16 −8 ICSharpCode.Decompiler/Ast/AstBuilder.cs
@@ -132,7 +132,7 @@ public TypeDeclaration CreateType(TypeDefinition typeDef)
TypeDeclaration astType = new TypeDeclaration();
astType.AddAnnotation(typeDef);
astType.Modifiers = ConvertModifiers(typeDef);
- astType.Name = typeDef.Name;
+ astType.Name = CleanName(typeDef.Name);
if (typeDef.IsEnum) { // NB: Enum is value type
astType.ClassType = ClassType.Enum;
@@ -165,7 +165,7 @@ public TypeDeclaration CreateType(TypeDefinition typeDef)
astType.AddChild(ConvertType(field.FieldType), TypeDeclaration.BaseTypeRole);
} else {
EnumMemberDeclaration enumMember = new EnumMemberDeclaration();
- enumMember.Name = field.Name;
+ enumMember.Name = CleanName(field.Name);
astType.AddChild(enumMember, TypeDeclaration.MemberRole);
}
}
@@ -184,6 +184,14 @@ public TypeDeclaration CreateType(TypeDefinition typeDef)
return astType;
}
+ string CleanName(string name)
+ {
+ int pos = name.LastIndexOf('`');
+ if (pos >= 0)
+ name = name.Substring(0, pos);
+ return name;
+ }
+
#region Convert Type Reference
/// <summary>
/// Converts a type reference.
@@ -453,7 +461,7 @@ MethodDeclaration CreateMethod(MethodDefinition methodDef)
MethodDeclaration astMethod = new MethodDeclaration();
astMethod.AddAnnotation(methodDef);
astMethod.ReturnType = ConvertType(methodDef.ReturnType, methodDef.MethodReturnType);
- astMethod.Name = methodDef.Name;
+ astMethod.Name = CleanName(methodDef.Name);
astMethod.TypeParameters.AddRange(MakeTypeParameters(methodDef.GenericParameters));
astMethod.Parameters.AddRange(MakeParameters(methodDef.Parameters));
astMethod.Constraints.AddRange(MakeConstraints(methodDef.GenericParameters));
@@ -468,7 +476,7 @@ IEnumerable<TypeParameterDeclaration> MakeTypeParameters(IEnumerable<GenericPara
{
return genericParameters.Select(
gp => new TypeParameterDeclaration {
- Name = gp.Name,
+ Name = CleanName(gp.Name),
Variance = gp.IsContravariant ? VarianceModifier.Contravariant : gp.IsCovariant ? VarianceModifier.Covariant : VarianceModifier.Invariant
});
}
@@ -488,7 +496,7 @@ ConstructorDeclaration CreateConstructor(MethodDefinition methodDef)
// don't show visibility for static ctors
astMethod.Modifiers &= ~Modifiers.VisibilityMask;
}
- astMethod.Name = methodDef.DeclaringType.Name;
+ astMethod.Name = CleanName(methodDef.DeclaringType.Name);
astMethod.Parameters.AddRange(MakeParameters(methodDef.Parameters));
astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context);
return astMethod;
@@ -499,7 +507,7 @@ PropertyDeclaration CreateProperty(PropertyDefinition propDef)
PropertyDeclaration astProp = new PropertyDeclaration();
astProp.AddAnnotation(propDef);
astProp.Modifiers = ConvertModifiers(propDef.GetMethod ?? propDef.SetMethod);
- astProp.Name = propDef.Name;
+ astProp.Name = CleanName(propDef.Name);
astProp.ReturnType = ConvertType(propDef.PropertyType, propDef);
if (propDef.GetMethod != null) {
astProp.Getter = new Accessor {
@@ -518,7 +526,7 @@ CustomEventDeclaration CreateEvent(EventDefinition eventDef)
{
CustomEventDeclaration astEvent = new CustomEventDeclaration();
astEvent.AddAnnotation(eventDef);
- astEvent.Name = eventDef.Name;
+ astEvent.Name = CleanName(eventDef.Name);
astEvent.ReturnType = ConvertType(eventDef.EventType, eventDef);
astEvent.Modifiers = ConvertModifiers(eventDef.AddMethod);
if (eventDef.AddMethod != null) {
@@ -538,7 +546,7 @@ FieldDeclaration CreateField(FieldDefinition fieldDef)
{
FieldDeclaration astField = new FieldDeclaration();
astField.AddAnnotation(fieldDef);
- VariableInitializer initializer = new VariableInitializer(fieldDef.Name);
+ VariableInitializer initializer = new VariableInitializer(CleanName(fieldDef.Name));
astField.AddChild(initializer, FieldDeclaration.Roles.Variable);
astField.ReturnType = ConvertType(fieldDef.FieldType, fieldDef);
astField.Modifiers = ConvertModifiers(fieldDef);

0 comments on commit f648be9

Please sign in to comment.