Browse Source

Fix #623: move public Analyze method to AnalyzerTreeView, so it is accessible from plugins.

pull/1213/head
Siegfried Pammer 8 years ago
parent
commit
3d510625dd
  1. 29
      ILSpy/Analyzers/AnalyzeContextMenuEntry.cs
  2. 32
      ILSpy/Analyzers/AnalyzerTreeView.cs

29
ILSpy/Analyzers/AnalyzeContextMenuEntry.cs

@ -57,35 +57,10 @@ namespace ICSharpCode.ILSpy.Analyzers
{ {
if (context.SelectedTreeNodes != null) { if (context.SelectedTreeNodes != null) {
foreach (IMemberTreeNode node in context.SelectedTreeNodes) { foreach (IMemberTreeNode node in context.SelectedTreeNodes) {
Analyze(node.Member); AnalyzerTreeView.Instance.Analyze(node.Member);
} }
} else if (context.Reference != null && context.Reference.Reference is IEntity entity) { } else if (context.Reference != null && context.Reference.Reference is IEntity entity) {
Analyze(entity); AnalyzerTreeView.Instance.Analyze(entity);
}
}
public static void Analyze(IEntity entity)
{
if (entity == null)
return;
switch (entity) {
case ITypeDefinition td:
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedTypeTreeNode(td));
break;
case IField fd:
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedFieldTreeNode(fd));
break;
case IMethod md:
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedMethodTreeNode(md));
break;
case IProperty pd:
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedPropertyTreeNode(pd));
break;
case IEvent ed:
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedEventTreeNode(ed));
break;
default:
throw new ArgumentOutOfRangeException(nameof(entity), $"Entity {entity.GetType().FullName} is not supported.");
} }
} }
} }

32
ILSpy/Analyzers/AnalyzerTreeView.cs

@ -16,10 +16,13 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.Analyzers.TreeNodes;
using ICSharpCode.TreeView; using ICSharpCode.TreeView;
namespace ICSharpCode.ILSpy.Analyzers namespace ICSharpCode.ILSpy.Analyzers
@ -82,7 +85,7 @@ namespace ICSharpCode.ILSpy.Analyzers
this.SelectedItem = node; this.SelectedItem = node;
this.FocusNode(node); this.FocusNode(node);
} }
public void ShowOrFocus(AnalyzerTreeNode node) public void ShowOrFocus(AnalyzerTreeNode node)
{ {
if (node is AnalyzerEntityTreeNode) { if (node is AnalyzerEntityTreeNode) {
@ -100,6 +103,33 @@ namespace ICSharpCode.ILSpy.Analyzers
Show(node); Show(node);
} }
public void Analyze(IEntity entity)
{
if (entity == null) {
throw new ArgumentNullException(nameof(entity));
}
switch (entity) {
case ITypeDefinition td:
ShowOrFocus(new AnalyzedTypeTreeNode(td));
break;
case IField fd:
ShowOrFocus(new AnalyzedFieldTreeNode(fd));
break;
case IMethod md:
ShowOrFocus(new AnalyzedMethodTreeNode(md));
break;
case IProperty pd:
ShowOrFocus(new AnalyzedPropertyTreeNode(pd));
break;
case IEvent ed:
ShowOrFocus(new AnalyzedEventTreeNode(ed));
break;
default:
throw new ArgumentOutOfRangeException(nameof(entity), $"Entity {entity.GetType().FullName} is not supported.");
}
}
void IPane.Closed() void IPane.Closed()
{ {
this.Root.Children.Clear(); this.Root.Children.Clear();

Loading…
Cancel
Save