From c9b1a85282413cde666d1329298e9dce7ca4dfb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ku=C4=8Dera?= Date: Sun, 22 Sep 2019 16:35:40 +0100 Subject: [PATCH] Add assembly search strategy --- ILSpy/ILSpy.csproj | 1 + ILSpy/Search/AssemblySearchStrategy.cs | 49 ++++++++++++++++++++++++++ ILSpy/Search/SearchPane.cs | 9 ++++- ILSpy/Search/SearchResult.cs | 9 +++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 ILSpy/Search/AssemblySearchStrategy.cs diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index 072b2c3ea..d4edc73a3 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -168,6 +168,7 @@ Resources.resx + diff --git a/ILSpy/Search/AssemblySearchStrategy.cs b/ILSpy/Search/AssemblySearchStrategy.cs new file mode 100644 index 000000000..fc27fa905 --- /dev/null +++ b/ILSpy/Search/AssemblySearchStrategy.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Threading; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using ICSharpCode.Decompiler.Metadata; +using ICSharpCode.Decompiler.TypeSystem; +using ICSharpCode.Decompiler.Util; +using ICSharpCode.ILSpy.TreeNodes; +using ICSharpCode.TreeView; + +namespace ICSharpCode.ILSpy.Search +{ + class AssemblySearchStrategy : AbstractSearchStrategy + { + public AssemblySearchStrategy(IProducerConsumerCollection resultQueue, string term) + : this(resultQueue, new[] { term }) + { + } + + public AssemblySearchStrategy(IProducerConsumerCollection resultQueue, string[] terms) + : base(resultQueue, terms) + { + } + + public override void Search(PEFile module, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + if (IsMatch(module.FullName)) + OnFoundResult(module); + } + + void OnFoundResult(PEFile module) + { + var result = new AssemblySearchResult { + Module = module, + Fitness = 1.0f / module.Name.Length, + Name = module.Name, + Location = module.FileName, + Assembly = module.FullName, + ToolTip = module.FileName, + }; + OnFoundResult(result); + } + } +} diff --git a/ILSpy/Search/SearchPane.cs b/ILSpy/Search/SearchPane.cs index f911fd3a6..e4139836f 100644 --- a/ILSpy/Search/SearchPane.cs +++ b/ILSpy/Search/SearchPane.cs @@ -76,6 +76,7 @@ namespace ICSharpCode.ILSpy searchModeComboBox.Items.Add(new { Image = Images.Literal, Name = "Constant" }); searchModeComboBox.Items.Add(new { Image = Images.Library, Name = "Metadata Token" }); searchModeComboBox.Items.Add(new { Image = Images.Resource, Name = "Resource" }); + searchModeComboBox.Items.Add(new { Image = Images.Assembly, Name = "Assembly" }); ContextMenuProvider.Add(listBox); MainWindow.Instance.CurrentAssemblyListChanged += MainWindow_Instance_CurrentAssemblyListChanged; @@ -345,6 +346,9 @@ namespace ICSharpCode.ILSpy if (searchTerm[0].StartsWith("r:", StringComparison.Ordinal)) return new ResourceSearchStrategy(apiVisibility, resultQueue, searchTerm[0].Substring(2)); + + if (searchTerm[0].StartsWith("a:", StringComparison.Ordinal)) + return new AssemblySearchStrategy(resultQueue, searchTerm[0].Substring(2)); } switch (searchMode) @@ -369,6 +373,8 @@ namespace ICSharpCode.ILSpy return new MetadataTokenSearchStrategy(language, apiVisibility, resultQueue, searchTerm); case SearchMode.Resource: return new ResourceSearchStrategy(apiVisibility, resultQueue, searchTerm); + case SearchMode.Assembly: + return new AssemblySearchStrategy(resultQueue, searchTerm); } return null; @@ -400,6 +406,7 @@ namespace ICSharpCode.ILSpy Event, Literal, Token, - Resource + Resource, + Assembly } } \ No newline at end of file diff --git a/ILSpy/Search/SearchResult.cs b/ILSpy/Search/SearchResult.cs index eb78c0bef..d632129f2 100644 --- a/ILSpy/Search/SearchResult.cs +++ b/ILSpy/Search/SearchResult.cs @@ -94,4 +94,13 @@ namespace ICSharpCode.ILSpy public Resource Resource { get; set; } public override object Reference => ValueTuple.Create(Resource, Name); } + + public class AssemblySearchResult : SearchResult + { + public PEFile Module { get; set; } + public override object Reference => Module; + + public override ImageSource Image => Images.Assembly; + public override ImageSource LocationImage => Images.Library; + } } \ No newline at end of file