Browse Source

Add AnalyzerContext.SortResults to allow sorted output of analysis results.

pull/2643/head
Siegfried Pammer 4 years ago
parent
commit
e62d6afcec
  1. 7
      ILSpy/Analyzers/AnalyzerContext.cs
  2. 7
      ILSpy/Analyzers/AnalyzerSearchTreeNode.cs

7
ILSpy/Analyzers/AnalyzerContext.cs

@ -43,6 +43,13 @@ namespace ICSharpCode.ILSpy.Analyzers @@ -43,6 +43,13 @@ namespace ICSharpCode.ILSpy.Analyzers
/// </summary>
public Language Language { get; internal set; }
/// <summary>
/// Allows the analyzer to control whether the tree nodes will be sorted.
/// Must be set within <see cref="IAnalyzer.Analyze(ISymbol, AnalyzerContext)"/>
/// before the results are enumerated.
/// </summary>
public bool SortResults { get; set; }
public MethodBodyBlock GetMethodBody(IMethod method)
{
if (!method.HasBody || method.MetadataToken.IsNil)

7
ILSpy/Analyzers/AnalyzerSearchTreeNode.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using ICSharpCode.Decompiler.TypeSystem;
@ -60,10 +61,12 @@ namespace ICSharpCode.ILSpy.Analyzers @@ -60,10 +61,12 @@ namespace ICSharpCode.ILSpy.Analyzers
Language = Language,
AssemblyList = MainWindow.Instance.CurrentAssemblyList
};
foreach (var result in analyzer.Analyze(symbol, context))
var results = analyzer.Analyze(symbol, context).Select(SymbolTreeNodeFactory);
if (context.SortResults)
{
yield return SymbolTreeNodeFactory(result);
results = results.OrderBy(tn => tn.Text?.ToString(), NaturalStringComparer.Instance);
}
return results;
}
else
{

Loading…
Cancel
Save