Browse Source

Add assembly search strategy

pull/1708/head
Jan Kučera 6 years ago
parent
commit
c9b1a85282
  1. 1
      ILSpy/ILSpy.csproj
  2. 49
      ILSpy/Search/AssemblySearchStrategy.cs
  3. 9
      ILSpy/Search/SearchPane.cs
  4. 9
      ILSpy/Search/SearchResult.cs

1
ILSpy/ILSpy.csproj

@ -168,6 +168,7 @@ @@ -168,6 +168,7 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Search\AbstractEntitySearchStrategy.cs" />
<Compile Include="Search\AssemblySearchStrategy.cs" />
<Compile Include="Search\LiteralSearchStrategy.cs" />
<Compile Include="LoadedAssembly.cs" />
<Compile Include="LoadedAssemblyExtensions.cs" />

49
ILSpy/Search/AssemblySearchStrategy.cs

@ -0,0 +1,49 @@ @@ -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<SearchResult> resultQueue, string term)
: this(resultQueue, new[] { term })
{
}
public AssemblySearchStrategy(IProducerConsumerCollection<SearchResult> 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);
}
}
}

9
ILSpy/Search/SearchPane.cs

@ -76,6 +76,7 @@ namespace ICSharpCode.ILSpy @@ -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 @@ -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 @@ -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 @@ -400,6 +406,7 @@ namespace ICSharpCode.ILSpy
Event,
Literal,
Token,
Resource
Resource,
Assembly
}
}

9
ILSpy/Search/SearchResult.cs

@ -94,4 +94,13 @@ namespace ICSharpCode.ILSpy @@ -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;
}
}
Loading…
Cancel
Save