Browse Source

Remove `n from generic class names.

pull/70/head
Daniel Grunwald 15 years ago
parent
commit
f648be9fb7
  1. 24
      ICSharpCode.Decompiler/Ast/AstBuilder.cs

24
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -132,7 +132,7 @@ namespace Decompiler
TypeDeclaration astType = new TypeDeclaration(); TypeDeclaration astType = new TypeDeclaration();
astType.AddAnnotation(typeDef); astType.AddAnnotation(typeDef);
astType.Modifiers = ConvertModifiers(typeDef); astType.Modifiers = ConvertModifiers(typeDef);
astType.Name = typeDef.Name; astType.Name = CleanName(typeDef.Name);
if (typeDef.IsEnum) { // NB: Enum is value type if (typeDef.IsEnum) { // NB: Enum is value type
astType.ClassType = ClassType.Enum; astType.ClassType = ClassType.Enum;
@ -165,7 +165,7 @@ namespace Decompiler
astType.AddChild(ConvertType(field.FieldType), TypeDeclaration.BaseTypeRole); astType.AddChild(ConvertType(field.FieldType), TypeDeclaration.BaseTypeRole);
} else { } else {
EnumMemberDeclaration enumMember = new EnumMemberDeclaration(); EnumMemberDeclaration enumMember = new EnumMemberDeclaration();
enumMember.Name = field.Name; enumMember.Name = CleanName(field.Name);
astType.AddChild(enumMember, TypeDeclaration.MemberRole); astType.AddChild(enumMember, TypeDeclaration.MemberRole);
} }
} }
@ -184,6 +184,14 @@ namespace Decompiler
return astType; return astType;
} }
string CleanName(string name)
{
int pos = name.LastIndexOf('`');
if (pos >= 0)
name = name.Substring(0, pos);
return name;
}
#region Convert Type Reference #region Convert Type Reference
/// <summary> /// <summary>
/// Converts a type reference. /// Converts a type reference.
@ -453,7 +461,7 @@ namespace Decompiler
MethodDeclaration astMethod = new MethodDeclaration(); MethodDeclaration astMethod = new MethodDeclaration();
astMethod.AddAnnotation(methodDef); astMethod.AddAnnotation(methodDef);
astMethod.ReturnType = ConvertType(methodDef.ReturnType, methodDef.MethodReturnType); astMethod.ReturnType = ConvertType(methodDef.ReturnType, methodDef.MethodReturnType);
astMethod.Name = methodDef.Name; astMethod.Name = CleanName(methodDef.Name);
astMethod.TypeParameters.AddRange(MakeTypeParameters(methodDef.GenericParameters)); astMethod.TypeParameters.AddRange(MakeTypeParameters(methodDef.GenericParameters));
astMethod.Parameters.AddRange(MakeParameters(methodDef.Parameters)); astMethod.Parameters.AddRange(MakeParameters(methodDef.Parameters));
astMethod.Constraints.AddRange(MakeConstraints(methodDef.GenericParameters)); astMethod.Constraints.AddRange(MakeConstraints(methodDef.GenericParameters));
@ -468,7 +476,7 @@ namespace Decompiler
{ {
return genericParameters.Select( return genericParameters.Select(
gp => new TypeParameterDeclaration { gp => new TypeParameterDeclaration {
Name = gp.Name, Name = CleanName(gp.Name),
Variance = gp.IsContravariant ? VarianceModifier.Contravariant : gp.IsCovariant ? VarianceModifier.Covariant : VarianceModifier.Invariant Variance = gp.IsContravariant ? VarianceModifier.Contravariant : gp.IsCovariant ? VarianceModifier.Covariant : VarianceModifier.Invariant
}); });
} }
@ -488,7 +496,7 @@ namespace Decompiler
// don't show visibility for static ctors // don't show visibility for static ctors
astMethod.Modifiers &= ~Modifiers.VisibilityMask; astMethod.Modifiers &= ~Modifiers.VisibilityMask;
} }
astMethod.Name = methodDef.DeclaringType.Name; astMethod.Name = CleanName(methodDef.DeclaringType.Name);
astMethod.Parameters.AddRange(MakeParameters(methodDef.Parameters)); astMethod.Parameters.AddRange(MakeParameters(methodDef.Parameters));
astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context); astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context);
return astMethod; return astMethod;
@ -499,7 +507,7 @@ namespace Decompiler
PropertyDeclaration astProp = new PropertyDeclaration(); PropertyDeclaration astProp = new PropertyDeclaration();
astProp.AddAnnotation(propDef); astProp.AddAnnotation(propDef);
astProp.Modifiers = ConvertModifiers(propDef.GetMethod ?? propDef.SetMethod); astProp.Modifiers = ConvertModifiers(propDef.GetMethod ?? propDef.SetMethod);
astProp.Name = propDef.Name; astProp.Name = CleanName(propDef.Name);
astProp.ReturnType = ConvertType(propDef.PropertyType, propDef); astProp.ReturnType = ConvertType(propDef.PropertyType, propDef);
if (propDef.GetMethod != null) { if (propDef.GetMethod != null) {
astProp.Getter = new Accessor { astProp.Getter = new Accessor {
@ -518,7 +526,7 @@ namespace Decompiler
{ {
CustomEventDeclaration astEvent = new CustomEventDeclaration(); CustomEventDeclaration astEvent = new CustomEventDeclaration();
astEvent.AddAnnotation(eventDef); astEvent.AddAnnotation(eventDef);
astEvent.Name = eventDef.Name; astEvent.Name = CleanName(eventDef.Name);
astEvent.ReturnType = ConvertType(eventDef.EventType, eventDef); astEvent.ReturnType = ConvertType(eventDef.EventType, eventDef);
astEvent.Modifiers = ConvertModifiers(eventDef.AddMethod); astEvent.Modifiers = ConvertModifiers(eventDef.AddMethod);
if (eventDef.AddMethod != null) { if (eventDef.AddMethod != null) {
@ -538,7 +546,7 @@ namespace Decompiler
{ {
FieldDeclaration astField = new FieldDeclaration(); FieldDeclaration astField = new FieldDeclaration();
astField.AddAnnotation(fieldDef); astField.AddAnnotation(fieldDef);
VariableInitializer initializer = new VariableInitializer(fieldDef.Name); VariableInitializer initializer = new VariableInitializer(CleanName(fieldDef.Name));
astField.AddChild(initializer, FieldDeclaration.Roles.Variable); astField.AddChild(initializer, FieldDeclaration.Roles.Variable);
astField.ReturnType = ConvertType(fieldDef.FieldType, fieldDef); astField.ReturnType = ConvertType(fieldDef.FieldType, fieldDef);
astField.Modifiers = ConvertModifiers(fieldDef); astField.Modifiers = ConvertModifiers(fieldDef);

Loading…
Cancel
Save