diff --git a/ILSpy/DebugSteps.xaml.cs b/ILSpy/DebugSteps.xaml.cs
index d2e5ae0fa..e5c1431e3 100644
--- a/ILSpy/DebugSteps.xaml.cs
+++ b/ILSpy/DebugSteps.xaml.cs
@@ -16,7 +16,7 @@ namespace ICSharpCode.ILSpy
public static ILAstWritingOptions Options => writingOptions;
-#if false
+#if DEBUG
ILAstLanguage language;
#endif
@@ -24,7 +24,7 @@ namespace ICSharpCode.ILSpy
{
InitializeComponent();
-#if false
+#if DEBUG
MainWindow.Instance.SessionSettings.FilterSettings.PropertyChanged += FilterSettings_PropertyChanged;
MainWindow.Instance.SelectionChanged += SelectionChanged;
writingOptions.PropertyChanged += WritingOptions_PropertyChanged;
@@ -52,7 +52,7 @@ namespace ICSharpCode.ILSpy
private void FilterSettings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
-#if false
+#if DEBUG
if (e.PropertyName == "Language") {
if (language != null) {
language.StepperUpdated -= ILAstStepperUpdated;
@@ -68,7 +68,7 @@ namespace ICSharpCode.ILSpy
private void ILAstStepperUpdated(object sender, EventArgs e)
{
-#if false
+#if DEBUG
if (language == null) return;
Dispatcher.Invoke(() => {
tree.ItemsSource = language.Stepper.Steps;
@@ -84,7 +84,7 @@ namespace ICSharpCode.ILSpy
void IPane.Closed()
{
-#if false
+#if DEBUG
MainWindow.Instance.SessionSettings.FilterSettings.PropertyChanged -= FilterSettings_PropertyChanged;
MainWindow.Instance.SelectionChanged -= SelectionChanged;
writingOptions.PropertyChanged -= WritingOptions_PropertyChanged;
diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj
index b4420f480..71e249aa4 100644
--- a/ILSpy/ILSpy.csproj
+++ b/ILSpy/ILSpy.csproj
@@ -120,6 +120,7 @@
+
@@ -130,8 +131,8 @@
+
-
diff --git a/ILSpy/Languages/CSharpILMixedLanguage.cs b/ILSpy/Languages/CSharpILMixedLanguage.cs
index 9c11200c1..c5d37efe0 100644
--- a/ILSpy/Languages/CSharpILMixedLanguage.cs
+++ b/ILSpy/Languages/CSharpILMixedLanguage.cs
@@ -38,7 +38,7 @@ using ICSharpCode.Decompiler.Util;
namespace ICSharpCode.ILSpy
{
- using SequencePoint = ICSharpCode.Decompiler.Metadata.SequencePoint;
+ using SequencePoint = ICSharpCode.Decompiler.DebugInfo.SequencePoint;
[Export(typeof(Language))]
class CSharpILMixedLanguage : ILLanguage
@@ -57,7 +57,7 @@ namespace ICSharpCode.ILSpy
static CSharpDecompiler CreateDecompiler(PEFile module, DecompilationOptions options)
{
- CSharpDecompiler decompiler = new CSharpDecompiler(module, options.DecompilerSettings);
+ CSharpDecompiler decompiler = new CSharpDecompiler(module, module.GetAssemblyResolver(), options.DecompilerSettings);
decompiler.CancellationToken = options.CancellationToken;
return decompiler;
}
diff --git a/ILSpy/Languages/ILAstLanguage.cs b/ILSpy/Languages/ILAstLanguage.cs
index 6dd6bb1ae..a7c0e1509 100644
--- a/ILSpy/Languages/ILAstLanguage.cs
+++ b/ILSpy/Languages/ILAstLanguage.cs
@@ -70,11 +70,11 @@ namespace ICSharpCode.ILSpy
}
}
- public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
+ public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options)
{
base.DecompileMethod(method, output, options);
- var module = method.Module;
- new ReflectionDisassembler(output, options.CancellationToken).DisassembleMethodHeader(module, method.Handle);
+ new ReflectionDisassembler(output, options.CancellationToken)
+ .DisassembleMethodHeader(method.ParentAssembly.PEFile, (SRM.MethodDefinitionHandle)method.MetadataToken);
output.WriteLine();
output.WriteLine();
}
@@ -83,17 +83,17 @@ namespace ICSharpCode.ILSpy
{
public TypedIL() : base("Typed IL") {}
- public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
+ public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options)
{
base.DecompileMethod(method, output, options);
- var metadata = method.Module.Metadata;
- var methodDef = metadata.GetMethodDefinition(method.Handle);
+ var module = method.ParentAssembly.PEFile;
+ var methodDef = module.Metadata.GetMethodDefinition((SRM.MethodDefinitionHandle)method.MetadataToken);
if (!methodDef.HasBody())
return;
- var typeSystem = new DecompilerTypeSystem(method.Module);
+ var typeSystem = new DecompilerTypeSystem(module, module.GetAssemblyResolver());
ILReader reader = new ILReader(typeSystem);
- var methodBody = method.Module.Reader.GetMethodBody(methodDef.RelativeVirtualAddress);
- reader.WriteTypedIL(method.Module, method.Handle, methodBody, output, options.CancellationToken);
+ var methodBody = module.Reader.GetMethodBody(methodDef.RelativeVirtualAddress);
+ reader.WriteTypedIL(module, (SRM.MethodDefinitionHandle)method.MetadataToken, methodBody, output, options.CancellationToken);
}
}
@@ -106,21 +106,23 @@ namespace ICSharpCode.ILSpy
this.transforms = transforms;
}
- public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
+ public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options)
{
base.DecompileMethod(method, output, options);
- var metadata = method.Module.Metadata;
- var methodDef = metadata.GetMethodDefinition(method.Handle);
+ var module = method.ParentAssembly.PEFile;
+ var metadata = module.Metadata;
+ var methodDef = metadata.GetMethodDefinition((SRM.MethodDefinitionHandle)method.MetadataToken);
if (!methodDef.HasBody())
return;
- var typeSystem = new DecompilerTypeSystem(method.Module);
- var specializingTypeSystem = typeSystem.GetSpecializingTypeSystem(new SimpleTypeResolveContext(typeSystem.ResolveAsMethod(method.Handle)));
+ IAssemblyResolver assemblyResolver = module.GetAssemblyResolver();
+ var typeSystem = new DecompilerTypeSystem(module, assemblyResolver);
+ var specializingTypeSystem = typeSystem.GetSpecializingTypeSystem(new SimpleTypeResolveContext(typeSystem.ResolveAsMethod(method.MetadataToken)));
var reader = new ILReader(specializingTypeSystem);
reader.UseDebugSymbols = options.DecompilerSettings.UseDebugSymbols;
- var methodBody = method.Module.Reader.GetMethodBody(methodDef.RelativeVirtualAddress);
- ILFunction il = reader.ReadIL(method.Module, method.Handle, methodBody, options.CancellationToken);
+ var methodBody = module.Reader.GetMethodBody(methodDef.RelativeVirtualAddress);
+ ILFunction il = reader.ReadIL(module, (SRM.MethodDefinitionHandle)method.MetadataToken, methodBody, options.CancellationToken);
var namespaces = new HashSet();
- var decompiler = new CSharpDecompiler(typeSystem, options.DecompilerSettings) { CancellationToken = options.CancellationToken };
+ var decompiler = new CSharpDecompiler(typeSystem, assemblyResolver, options.DecompilerSettings) { CancellationToken = options.CancellationToken };
ILTransformContext context = decompiler.CreateILTransformContext(il);
context.Stepper.StepLimit = options.StepLimit;
context.Stepper.IsDebug = options.IsDebug;
diff --git a/ILSpy/Languages/ILLanguage.cs b/ILSpy/Languages/ILLanguage.cs
index 3b63b4d47..290a023d1 100644
--- a/ILSpy/Languages/ILLanguage.cs
+++ b/ILSpy/Languages/ILLanguage.cs
@@ -63,19 +63,19 @@ namespace ICSharpCode.ILSpy
public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options)
{
var dis = CreateDisassembler(output, options);
- dis.DisassembleMethod(((MetadataAssembly)method.ParentAssembly).PEFile, (MethodDefinitionHandle)method.MetadataToken);
+ dis.DisassembleMethod(method.ParentAssembly.PEFile, (MethodDefinitionHandle)method.MetadataToken);
}
public override void DecompileField(IField field, ITextOutput output, DecompilationOptions options)
{
var dis = CreateDisassembler(output, options);
- dis.DisassembleField(((MetadataAssembly)field.ParentAssembly).PEFile, (FieldDefinitionHandle)field.MetadataToken);
+ dis.DisassembleField(field.ParentAssembly.PEFile, (FieldDefinitionHandle)field.MetadataToken);
}
public override void DecompileProperty(IProperty property, ITextOutput output, DecompilationOptions options)
{
var dis = CreateDisassembler(output, options);
- PEFile module = ((MetadataAssembly)property.ParentAssembly).PEFile;
+ PEFile module = property.ParentAssembly.PEFile;
dis.DisassembleProperty(module, (PropertyDefinitionHandle)property.MetadataToken);
var pd = module.Metadata.GetPropertyDefinition((PropertyDefinitionHandle)property.MetadataToken);
var accessors = pd.GetAccessors();
@@ -97,7 +97,7 @@ namespace ICSharpCode.ILSpy
public override void DecompileEvent(IEvent ev, ITextOutput output, DecompilationOptions options)
{
var dis = CreateDisassembler(output, options);
- PEFile module = ((MetadataAssembly)ev.ParentAssembly).PEFile;
+ PEFile module = ev.ParentAssembly.PEFile;
dis.DisassembleEvent(module, (EventDefinitionHandle)ev.MetadataToken);
var ed = ((MetadataReader)module.Metadata).GetEventDefinition((EventDefinitionHandle)ev.MetadataToken);
@@ -123,14 +123,14 @@ namespace ICSharpCode.ILSpy
public override void DecompileType(ITypeDefinition type, ITextOutput output, DecompilationOptions options)
{
var dis = CreateDisassembler(output, options);
- PEFile module = ((MetadataAssembly)type.ParentAssembly).PEFile;
+ PEFile module = type.ParentAssembly.PEFile;
dis.DisassembleType(module, (TypeDefinitionHandle)type.MetadataToken);
}
public override void DecompileNamespace(string nameSpace, IEnumerable types, ITextOutput output, DecompilationOptions options)
{
var dis = CreateDisassembler(output, options);
- PEFile module = ((MetadataAssembly)types.FirstOrDefault()?.ParentAssembly)?.PEFile;
+ PEFile module = types.FirstOrDefault()?.ParentAssembly.PEFile;
dis.DisassembleNamespace(nameSpace, module, types.Select(t => (TypeDefinitionHandle)t.MetadataToken));
}
diff --git a/ILSpy/Languages/ILSignatureProvider.cs b/ILSpy/Languages/ILSignatureProvider.cs
deleted file mode 100644
index 3750461e8..000000000
--- a/ILSpy/Languages/ILSignatureProvider.cs
+++ /dev/null
@@ -1,172 +0,0 @@
-// 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.Collections.Immutable;
-using ICSharpCode.Decompiler;
-using ICSharpCode.Decompiler.Metadata;
-using SRM = System.Reflection.Metadata;
-
-namespace ICSharpCode.ILSpy
-{
- class ILSignatureProvider : SRM.ISignatureTypeProvider
- {
- public static readonly ILSignatureProvider WithoutNamespace = new ILSignatureProvider(false);
- public static readonly ILSignatureProvider WithNamespace = new ILSignatureProvider(true);
-
- bool includeNamespace;
-
- public ILSignatureProvider(bool includeNamespace)
- {
- this.includeNamespace = includeNamespace;
- }
-
- public string GetArrayType(string elementType, SRM.ArrayShape shape)
- {
- string printedShape = "";
- for (int i = 0; i < shape.Rank; i++) {
- if (i > 0)
- printedShape += ", ";
- if (i < shape.LowerBounds.Length || i < shape.Sizes.Length) {
- int lower = 0;
- if (i < shape.LowerBounds.Length) {
- lower = shape.LowerBounds[i];
- printedShape += lower.ToString();
- }
- printedShape += "...";
- if (i < shape.Sizes.Length)
- printedShape += (lower + shape.Sizes[i] - 1).ToString();
- }
- }
- return $"{elementType}[{printedShape}]";
- }
-
- public string GetByReferenceType(string elementType)
- {
- return elementType + "&";
- }
-
- public string GetFunctionPointerType(SRM.MethodSignature signature)
- {
- return "method " + signature.ReturnType + " *(" + string.Join(", ", signature.ParameterTypes) + ")";
- }
-
- public string GetGenericInstantiation(string genericType, ImmutableArray typeArguments)
- {
- return genericType + "<" + string.Join(", ", typeArguments) + ">";
- }
-
- public string GetGenericMethodParameter(GenericContext genericContext, int index)
- {
- return "!!" + genericContext.GetGenericMethodTypeParameterName(index);
- }
-
- public string GetGenericTypeParameter(GenericContext genericContext, int index)
- {
- return "!" + genericContext.GetGenericTypeParameterName(index);
- }
-
- public string GetModifiedType(string modifier, string unmodifiedType, bool isRequired)
- {
- string modifierKeyword = isRequired ? "modreq" : "modopt";
- return $"{unmodifiedType} {modifierKeyword}({modifier})";
- }
-
- public string GetPinnedType(string elementType)
- {
- throw new NotImplementedException();
- }
-
- public string GetPointerType(string elementType)
- {
- return elementType + "*";
- }
-
- public string GetPrimitiveType(SRM.PrimitiveTypeCode typeCode)
- {
- switch (typeCode) {
- case SRM.PrimitiveTypeCode.Boolean:
- return "bool";
- case SRM.PrimitiveTypeCode.Byte:
- return "uint8";
- case SRM.PrimitiveTypeCode.SByte:
- return "int8";
- case SRM.PrimitiveTypeCode.Char:
- return "char";
- case SRM.PrimitiveTypeCode.Int16:
- return "int16";
- case SRM.PrimitiveTypeCode.UInt16:
- return "uint16";
- case SRM.PrimitiveTypeCode.Int32:
- return "int32";
- case SRM.PrimitiveTypeCode.UInt32:
- return "uint32";
- case SRM.PrimitiveTypeCode.Int64:
- return "int64";
- case SRM.PrimitiveTypeCode.UInt64:
- return "uint64";
- case SRM.PrimitiveTypeCode.Single:
- return "float32";
- case SRM.PrimitiveTypeCode.Double:
- return "float64";
- case SRM.PrimitiveTypeCode.IntPtr:
- return "native int";
- case SRM.PrimitiveTypeCode.UIntPtr:
- return "native uint";
- case SRM.PrimitiveTypeCode.Object:
- return "object";
- case SRM.PrimitiveTypeCode.String:
- return "string";
- case SRM.PrimitiveTypeCode.TypedReference:
- return "typedref";
- case SRM.PrimitiveTypeCode.Void:
- return "void";
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
-
- public string GetSZArrayType(string elementType)
- {
- return elementType + "[]";
- }
-
- public string GetTypeFromDefinition(SRM.MetadataReader reader, SRM.TypeDefinitionHandle handle, byte rawTypeKind)
- {
- if (!includeNamespace) {
- return Decompiler.Disassembler.DisassemblerHelpers.Escape(handle.GetFullTypeName(reader).Name);
- }
-
- return handle.GetFullTypeName(reader).ToILNameString();
- }
-
- public string GetTypeFromReference(SRM.MetadataReader reader, SRM.TypeReferenceHandle handle, byte rawTypeKind)
- {
- if (!includeNamespace) {
- return Decompiler.Disassembler.DisassemblerHelpers.Escape(handle.GetFullTypeName(reader).Name);
- }
-
- return handle.GetFullTypeName(reader).ToILNameString();
- }
-
- public string GetTypeFromSpecification(SRM.MetadataReader reader, GenericContext genericContext, SRM.TypeSpecificationHandle handle, byte rawTypeKind)
- {
- return reader.GetTypeSpecification(handle).DecodeSignature(this, genericContext);
- }
- }
-}
diff --git a/ILSpy/SearchStrategies.cs b/ILSpy/SearchStrategies.cs
index 907d72145..df3926420 100644
--- a/ILSpy/SearchStrategies.cs
+++ b/ILSpy/SearchStrategies.cs
@@ -163,7 +163,7 @@ namespace ICSharpCode.ILSpy
{
switch (member) {
case ITypeDefinition t:
- return language.TypeToString(t, includeNamespace: fullName);
+ return language.TypeDefinitionToString(t, includeNamespace: fullName);
case IField f:
return language.FieldToString(f, fullName, fullName);
case IProperty p:
@@ -193,7 +193,7 @@ namespace ICSharpCode.ILSpy
Image = image(item),
Name = GetLanguageSpecificName(language, item),
LocationImage = TypeTreeNode.GetIcon(type),
- Location = language.TypeToString(type, includeNamespace: true)
+ Location = language.TypeDefinitionToString(type, includeNamespace: true)
});
}
}
@@ -497,7 +497,7 @@ namespace ICSharpCode.ILSpy
public override void Search(ITypeDefinition type, Language language, Action addResult)
{
if (MatchName(type, language)) {
- string name = language.TypeToString(type, includeNamespace: false);
+ string name = language.TypeDefinitionToString(type, includeNamespace: false);
var declaringType = type.DeclaringTypeDefinition;
addResult(new SearchResult {
Member = type,
@@ -505,7 +505,7 @@ namespace ICSharpCode.ILSpy
Image = TypeTreeNode.GetIcon(type),
Name = name,
LocationImage = declaringType != null ? TypeTreeNode.GetIcon(declaringType) : Images.Namespace,
- Location = declaringType != null ? language.TypeToString(declaringType, includeNamespace: true) : type.Namespace
+ Location = declaringType != null ? language.TypeDefinitionToString(declaringType, includeNamespace: true) : type.Namespace
});
}
@@ -526,7 +526,7 @@ namespace ICSharpCode.ILSpy
{
if (MatchName(type, language))
{
- string name = language.TypeToString(type, includeNamespace: false);
+ string name = language.TypeDefinitionToString(type, includeNamespace: false);
var declaringType = type.DeclaringTypeDefinition;
addResult(new SearchResult {
Member = type,
@@ -534,7 +534,7 @@ namespace ICSharpCode.ILSpy
Fitness = CalculateFitness(type),
Name = name,
LocationImage = declaringType != null ? TypeTreeNode.GetIcon(declaringType) : Images.Namespace,
- Location = declaringType != null ? language.TypeToString(declaringType, includeNamespace: true) : type.Namespace
+ Location = declaringType != null ? language.TypeDefinitionToString(declaringType, includeNamespace: true) : type.Namespace
});
}