Browse Source

Use C# syntax for type names in the tree view.

pull/10/head
Daniel Grunwald 15 years ago
parent
commit
17d9501299
  1. 40
      ILSpy/CSharpLanguage.cs
  2. 4
      ILSpy/ILLanguage.cs
  3. 17
      ILSpy/Language.cs
  4. 2
      ILSpy/TreeNodes/BaseTypesTreeNode.cs
  5. 4
      ILSpy/TreeNodes/DerivedTypesTreeNode.cs
  6. 2
      ILSpy/TreeNodes/EventTreeNode.cs
  7. 2
      ILSpy/TreeNodes/FieldTreeNode.cs
  8. 4
      ILSpy/TreeNodes/MethodTreeNode.cs
  9. 2
      ILSpy/TreeNodes/PropertyTreeNode.cs

40
ILSpy/CSharpLanguage.cs

@ -17,8 +17,11 @@ @@ -17,8 +17,11 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using System.Linq;
using Decompiler;
using ICSharpCode.Decompiler;
using ICSharpCode.NRefactory.CSharp;
using Mono.Cecil;
namespace ICSharpCode.ILSpy
@ -70,5 +73,42 @@ namespace ICSharpCode.ILSpy @@ -70,5 +73,42 @@ namespace ICSharpCode.ILSpy
codeDomBuilder.AddType(type);
codeDomBuilder.GenerateCode(output);
}
public override string TypeToString(TypeReference type, bool includeNamespace, ICustomAttributeProvider typeAttributes)
{
AstType astType = AstBuilder.ConvertType(type, typeAttributes);
if (!includeNamespace) {
var tre = new TypeReferenceExpression { Type = astType };
tre.AcceptVisitor(new RemoveNamespaceFromType(), null);
astType = tre.Type;
}
StringWriter w = new StringWriter();
if (type.IsByReference) {
ParameterDefinition pd = typeAttributes as ParameterDefinition;
if (pd != null && (!pd.IsIn && pd.IsOut))
w.Write("out ");
else
w.Write("ref ");
}
astType.AcceptVisitor(new OutputVisitor(w, new CSharpFormattingPolicy()), null);
return w.ToString();
}
sealed class RemoveNamespaceFromType : DepthFirstAstVisitor<object, object>
{
public override object VisitMemberType(MemberType memberType, object data)
{
base.VisitMemberType(memberType, data);
SimpleType st = memberType.Target as SimpleType;
if (st != null && !st.TypeArguments.Any()) {
var ta = memberType.TypeArguments.ToArray();
memberType.TypeArguments = null;
memberType.ReplaceWith(new SimpleType { Identifier = memberType.MemberName, TypeArguments = ta });
}
return null;
}
}
}
}

4
ILSpy/ILLanguage.cs

@ -88,10 +88,10 @@ namespace ICSharpCode.ILSpy @@ -88,10 +88,10 @@ namespace ICSharpCode.ILSpy
new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken).WriteAssemblyHeader(assembly);
}
public override string TypeToString(TypeReference t)
public override string TypeToString(TypeReference t, bool includeNamespace, ICustomAttributeProvider attributeProvider)
{
PlainTextOutput output = new PlainTextOutput();
t.WriteTo(output, true, true);
t.WriteTo(output, true, shortName: !includeNamespace);
return output.ToString();
}
}

17
ILSpy/Language.cs

@ -51,27 +51,27 @@ namespace ICSharpCode.ILSpy @@ -51,27 +51,27 @@ namespace ICSharpCode.ILSpy
public virtual void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
{
WriteCommentLine(output, TypeToString(method.DeclaringType) + "." + method.Name);
WriteCommentLine(output, TypeToString(method.DeclaringType, true) + "." + method.Name);
}
public virtual void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilationOptions options)
{
WriteCommentLine(output, TypeToString(property.DeclaringType) + "." + property.Name);
WriteCommentLine(output, TypeToString(property.DeclaringType, true) + "." + property.Name);
}
public virtual void DecompileField(FieldDefinition field, ITextOutput output, DecompilationOptions options)
{
WriteCommentLine(output, TypeToString(field.DeclaringType) + "." + field.Name);
WriteCommentLine(output, TypeToString(field.DeclaringType, true) + "." + field.Name);
}
public virtual void DecompileEvent(EventDefinition ev, ITextOutput output, DecompilationOptions options)
{
WriteCommentLine(output, TypeToString(ev.DeclaringType) + "." + ev.Name);
WriteCommentLine(output, TypeToString(ev.DeclaringType, true) + "." + ev.Name);
}
public virtual void DecompileType(TypeDefinition type, ITextOutput output, DecompilationOptions options)
{
WriteCommentLine(output, TypeToString(type));
WriteCommentLine(output, TypeToString(type, true));
}
public virtual void DecompileNamespace(string nameSpace, IEnumerable<TypeDefinition> types, ITextOutput output, DecompilationOptions options)
@ -93,9 +93,12 @@ namespace ICSharpCode.ILSpy @@ -93,9 +93,12 @@ namespace ICSharpCode.ILSpy
/// <summary>
/// Converts a type reference into a string. This method is used by the member tree node for parameter and return types.
/// </summary>
public virtual string TypeToString(TypeReference t)
public virtual string TypeToString(TypeReference type, bool includeNamespace, ICustomAttributeProvider typeAttributes = null)
{
return t.Name;
if (includeNamespace)
return type.FullName;
else
return type.Name;
}
/// <summary>

2
ILSpy/TreeNodes/BaseTypesTreeNode.cs

@ -136,7 +136,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -136,7 +136,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, language.TypeToString(tr));
language.WriteCommentLine(output, language.TypeToString(tr, true));
}
}
}

4
ILSpy/TreeNodes/DerivedTypesTreeNode.cs

@ -51,7 +51,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -51,7 +51,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
if (IsSameType(typeRef, type))
children.Add(new DerivedTypesEntryNode(td, list));
}
} else if (!type.IsInterface && IsSameType(td.BaseType, type)) {
} else if (!type.IsInterface && td.BaseType != null && IsSameType(td.BaseType, type)) {
children.Add(new DerivedTypesEntryNode(td, list));
}
}
@ -112,7 +112,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -112,7 +112,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, language.TypeToString(def));
language.WriteCommentLine(output, language.TypeToString(def, true));
}
}
}

2
ILSpy/TreeNodes/EventTreeNode.cs

@ -42,7 +42,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -42,7 +42,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
public override object Text {
get { return HighlightSearchMatch(ev.Name, " : " + this.Language.TypeToString(ev.EventType)); }
get { return HighlightSearchMatch(ev.Name, " : " + this.Language.TypeToString(ev.EventType, false, ev)); }
}
public override object Icon {

2
ILSpy/TreeNodes/FieldTreeNode.cs

@ -41,7 +41,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -41,7 +41,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
public override object Text {
get { return HighlightSearchMatch(field.Name, " : " + this.Language.TypeToString(field.FieldType)); }
get { return HighlightSearchMatch(field.Name, " : " + this.Language.TypeToString(field.FieldType, false, field)); }
}
public override object Icon {

4
ILSpy/TreeNodes/MethodTreeNode.cs

@ -47,10 +47,10 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -47,10 +47,10 @@ namespace ICSharpCode.ILSpy.TreeNodes
b.Append('(');
for (int i = 0; i < method.Parameters.Count; i++) {
if (i > 0) b.Append(", ");
b.Append(this.Language.TypeToString(method.Parameters[i].ParameterType));
b.Append(this.Language.TypeToString(method.Parameters[i].ParameterType, false, method.Parameters[i]));
}
b.Append(") : ");
b.Append(this.Language.TypeToString(method.ReturnType));
b.Append(this.Language.TypeToString(method.ReturnType, false, method.MethodReturnType));
return HighlightSearchMatch(method.Name, b.ToString());
}
}

2
ILSpy/TreeNodes/PropertyTreeNode.cs

@ -44,7 +44,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -44,7 +44,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
public override object Text {
get { return HighlightSearchMatch(property.Name, " : " + this.Language.TypeToString(property.PropertyType)); }
get { return HighlightSearchMatch(property.Name, " : " + this.Language.TypeToString(property.PropertyType, false, property)); }
}
public override object Icon {

Loading…
Cancel
Save