Browse Source

print assembly attributes when selecting Assemlby node

pull/254/head
Siegfried Pammer 14 years ago
parent
commit
e5d63e9761
  1. 1
      ILSpy/ILSpy.csproj
  2. 67
      ILSpy/VB/ILSpyEnvironmentProvider.cs
  3. 101
      ILSpy/VB/VBLanguage.cs

1
ILSpy/ILSpy.csproj

@ -188,6 +188,7 @@ @@ -188,6 +188,7 @@
<Compile Include="TreeNodes\ResourceNodes\XamlResourceNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedPropertyOverridesTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedPropertyTreeNode.cs" />
<Compile Include="VB\ILSpyEnvironmentProvider.cs" />
<Compile Include="VB\VBLanguage.cs" />
<Compile Include="VB\VBTextOutputFormatter.cs" />
<Compile Include="XmlDoc\AddXmlDocTransform.cs" />

67
ILSpy/VB/ILSpyEnvironmentProvider.cs

@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Linq;
using ICSharpCode.Decompiler;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.VB.Visitors;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.VB
{
public class ILSpyEnvironmentProvider : IEnvironmentProvider
{
public string RootNamespace {
get {
return "";
}
}
public string GetTypeNameForAttribute(ICSharpCode.NRefactory.CSharp.Attribute attribute)
{
return attribute.Type.Annotations
.OfType<Mono.Cecil.MemberReference>()
.First()
.FullName;
}
public ClassType GetClassTypeForAstType(ICSharpCode.NRefactory.CSharp.AstType type)
{
var definition = type.Annotations.OfType<TypeReference>().First().ResolveOrThrow();
if (definition.IsClass)
return ClassType.Class;
if (definition.IsInterface)
return ClassType.Interface;
if (definition.IsEnum)
return ClassType.Enum;
if (definition.IsFunctionPointer)
return ClassType.Delegate;
if (definition.IsValueType)
return ClassType.Struct;
return ClassType.Module;
}
public IType ResolveExpression(ICSharpCode.NRefactory.CSharp.Expression expression)
{
throw new NotImplementedException();
}
}
}

101
ILSpy/VB/VBLanguage.cs

@ -17,10 +17,12 @@ @@ -17,10 +17,12 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Text;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Ast;
using ICSharpCode.Decompiler.Ast.Transforms;
@ -62,6 +64,65 @@ namespace ICSharpCode.ILSpy.VB @@ -62,6 +64,65 @@ namespace ICSharpCode.ILSpy.VB
output.WriteLine("' " + comment);
}
public override void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
{
if (options.FullDecompilation && options.SaveAsProjectDirectory != null) {
// HashSet<string> directories = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
// var files = WriteCodeFilesInProject(assembly.AssemblyDefinition, options, directories).ToList();
// files.AddRange(WriteResourceFilesInProject(assembly, options, directories));
// WriteProjectFile(new TextOutputWriter(output), files, assembly.AssemblyDefinition.MainModule);
} else {
base.DecompileAssembly(assembly, output, options);
output.WriteLine();
ModuleDefinition mainModule = assembly.AssemblyDefinition.MainModule;
if (mainModule.EntryPoint != null) {
output.Write("' Entry point: ");
output.WriteReference(mainModule.EntryPoint.DeclaringType.FullName + "." + mainModule.EntryPoint.Name, mainModule.EntryPoint);
output.WriteLine();
}
switch (mainModule.Architecture) {
case TargetArchitecture.I386:
if ((mainModule.Attributes & ModuleAttributes.Required32Bit) == ModuleAttributes.Required32Bit)
WriteCommentLine(output, "Architecture: x86");
else
WriteCommentLine(output, "Architecture: AnyCPU");
break;
case TargetArchitecture.AMD64:
WriteCommentLine(output, "Architecture: x64");
break;
case TargetArchitecture.IA64:
WriteCommentLine(output, "Architecture: Itanium-64");
break;
}
if ((mainModule.Attributes & ModuleAttributes.ILOnly) == 0) {
WriteCommentLine(output, "This assembly contains unmanaged code.");
}
switch (mainModule.Runtime) {
case TargetRuntime.Net_1_0:
WriteCommentLine(output, "Runtime: .NET 1.0");
break;
case TargetRuntime.Net_1_1:
WriteCommentLine(output, "Runtime: .NET 1.1");
break;
case TargetRuntime.Net_2_0:
WriteCommentLine(output, "Runtime: .NET 2.0");
break;
case TargetRuntime.Net_4_0:
WriteCommentLine(output, "Runtime: .NET 4.0");
break;
}
output.WriteLine();
// don't automatically load additional assemblies when an assembly node is selected in the tree view
using (options.FullDecompilation ? null : LoadedAssembly.DisableAssemblyLoad()) {
AstBuilder codeDomBuilder = CreateAstBuilder(options, currentModule: assembly.AssemblyDefinition.MainModule);
codeDomBuilder.AddAssembly(assembly.AssemblyDefinition, onlyAssemblyLevel: !options.FullDecompilation);
RunTransformsAndGenerateCode(codeDomBuilder, output, options);
}
}
OnDecompilationFinished(null);
}
public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
{
WriteCommentLine(output, TypeToString(method.DeclaringType, includeNamespace: true));
@ -162,44 +223,4 @@ namespace ICSharpCode.ILSpy.VB @@ -162,44 +223,4 @@ namespace ICSharpCode.ILSpy.VB
return w.ToString();
}
}
public class ILSpyEnvironmentProvider : IEnvironmentProvider
{
public string RootNamespace {
get {
return "";
}
}
public string GetTypeNameForAttribute(ICSharpCode.NRefactory.CSharp.Attribute attribute)
{
return attribute.Type.Annotations
.OfType<Mono.Cecil.MemberReference>()
.First()
.FullName;
}
public ClassType GetClassTypeForAstType(ICSharpCode.NRefactory.CSharp.AstType type)
{
var definition = type.Annotations.OfType<TypeReference>().First().ResolveOrThrow();
if (definition.IsClass)
return ClassType.Class;
if (definition.IsInterface)
return ClassType.Interface;
if (definition.IsEnum)
return ClassType.Enum;
if (definition.IsFunctionPointer)
return ClassType.Delegate;
if (definition.IsValueType)
return ClassType.Struct;
return ClassType.Module;
}
public IType ResolveExpression(ICSharpCode.NRefactory.CSharp.Expression expression)
{
throw new NotImplementedException();
}
}
}

Loading…
Cancel
Save