diff --git a/ILSpy/Commands/DecompileCommand.cs b/ILSpy/Commands/DecompileCommand.cs index 5980cf319..24c6c4180 100644 --- a/ILSpy/Commands/DecompileCommand.cs +++ b/ILSpy/Commands/DecompileCommand.cs @@ -1,20 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; +// 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 System.Reflection; -using System.Reflection.Metadata; using System.Reflection.Metadata.Ecma335; -using System.Text; -using System.Threading.Tasks; -using System.Windows; using System.Windows.Controls; -using System.Windows.Input; -using System.Windows.Media; using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.TypeSystem; -using ICSharpCode.ILSpy.Analyzers; -using ICSharpCode.ILSpy.Controls; using ICSharpCode.ILSpy.Metadata; using ICSharpCode.ILSpy.TreeNodes; @@ -66,7 +74,7 @@ namespace ICSharpCode.ILSpy.Commands public void Execute(TextViewContext context) { int token = GetSelectedToken(context.DataGrid, out PEFile module).Value; - MainWindow.Instance.JumpToReference(("metadata", module, MetadataTokens.Handle(token))); + MainWindow.Instance.JumpToReference(new EntityReference("metadata", module, MetadataTokens.Handle(token))); } public bool IsEnabled(TextViewContext context) diff --git a/ILSpy/EntityReference.cs b/ILSpy/EntityReference.cs new file mode 100644 index 000000000..a4ef94704 --- /dev/null +++ b/ILSpy/EntityReference.cs @@ -0,0 +1,45 @@ +// Copyright (c) 2018 Siegfried Pammer +// +// 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.Diagnostics; +using System.Reflection.Metadata; +using ICSharpCode.Decompiler.Metadata; + +namespace ICSharpCode.ILSpy +{ + [DebuggerDisplay("EntityReference Module={Module}, Handle={Handle}, Protocol={Protocol}")] + public class EntityReference + { + public PEFile Module { get; } + public Handle Handle { get; } + public string Protocol { get; } + + public EntityReference(PEFile module, Handle handle) + { + this.Module = module ?? throw new ArgumentNullException(nameof(module)); + this.Handle = handle; + } + + public EntityReference(string protocol, PEFile module, Handle handle) + : this(module, handle) + { + this.Protocol = protocol ?? "decompile"; + } + } +} diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index e8c721f97..201719e62 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -138,6 +138,7 @@ + Code MSBuild:Compile diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index c069d47b8..ef311f68a 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -885,22 +885,22 @@ namespace ICSharpCode.ILSpy case Decompiler.Disassembler.OpCodeInfo opCode: OpenLink(opCode.Link); break; - case ValueTuple unresolvedEntity: - string protocol = unresolvedEntity.Item1 ?? "decompile"; - PEFile file = unresolvedEntity.Item2; + case EntityReference unresolvedEntity: + string protocol = unresolvedEntity.Protocol ?? "decompile"; + PEFile file = unresolvedEntity.Module; if (protocol != "decompile") { var protocolHandlers = App.ExportProvider.GetExports(); foreach (var handler in protocolHandlers) { - var node = handler.Value.Resolve(protocol, file, unresolvedEntity.Item3, out bool newTabPage); + var node = handler.Value.Resolve(protocol, file, unresolvedEntity.Handle, out bool newTabPage); if (node != null) { SelectNode(node, newTabPage); return decompilationTask; } } } - if (MetadataTokenHelpers.TryAsEntityHandle(MetadataTokens.GetToken(unresolvedEntity.Item3)) != null) { + if (MetadataTokenHelpers.TryAsEntityHandle(MetadataTokens.GetToken(unresolvedEntity.Handle)) != null) { var typeSystem = new DecompilerTypeSystem(file, file.GetAssemblyResolver(), TypeSystemOptions.Default | TypeSystemOptions.Uncached); - reference = typeSystem.MainModule.ResolveEntity((EntityHandle)unresolvedEntity.Item3); + reference = typeSystem.MainModule.ResolveEntity((EntityHandle)unresolvedEntity.Handle); goto default; } break; diff --git a/ILSpy/TextView/AvalonEditTextOutput.cs b/ILSpy/TextView/AvalonEditTextOutput.cs index 15c3f25a6..5c2bb7203 100644 --- a/ILSpy/TextView/AvalonEditTextOutput.cs +++ b/ILSpy/TextView/AvalonEditTextOutput.cs @@ -245,7 +245,7 @@ namespace ICSharpCode.ILSpy.TextView if (isDefinition) { this.DefinitionLookup.AddDefinition((module, handle), this.TextLength); } - references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = (protocol, module, handle), IsDefinition = isDefinition }); + references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = new EntityReference(protocol, module, handle), IsDefinition = isDefinition }); } public void WriteReference(IType type, string text, bool isDefinition = false) diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index feb9f0a7b..91ac810a8 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -362,10 +362,10 @@ namespace ICSharpCode.ILSpy.TextView if (document == null) return null; return new FlowDocumentTooltip(document); - } else if (segment.Reference is ValueTuple unresolvedEntity) { - var typeSystem = new DecompilerTypeSystem(unresolvedEntity.Item1, unresolvedEntity.Item1.GetAssemblyResolver(), TypeSystemOptions.Default | TypeSystemOptions.Uncached); + } else if (segment.Reference is EntityReference unresolvedEntity) { + var typeSystem = new DecompilerTypeSystem(unresolvedEntity.Module, unresolvedEntity.Module.GetAssemblyResolver(), TypeSystemOptions.Default | TypeSystemOptions.Uncached); try { - IEntity resolved = typeSystem.MainModule.ResolveEntity(unresolvedEntity.Item2); + IEntity resolved = typeSystem.MainModule.ResolveEntity(unresolvedEntity.Handle); if (resolved == null) return null; var document = CreateTooltipForEntity(resolved);