Browse Source

Fix #1842: NullReferenceException in DecompileInNewViewCommand

pull/1880/head
Siegfried Pammer 6 years ago
parent
commit
66843ff312
  1. 19
      ILSpy/Commands/DecompileInNewViewCommand.cs

19
ILSpy/Commands/DecompileInNewViewCommand.cs

@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows.Threading; using System.Windows.Threading;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
@ -37,24 +38,28 @@ namespace ICSharpCode.ILSpy.Commands
public bool IsEnabled(TextViewContext context) public bool IsEnabled(TextViewContext context)
{ {
return context.SelectedTreeNodes != null || context.Reference?.Reference is IEntity; return GetNodes(context).Any();
} }
public void Execute(TextViewContext context) public void Execute(TextViewContext context)
{
DecompileNodes(GetNodes(context).ToArray());
}
IEnumerable<ILSpyTreeNode> GetNodes(TextViewContext context)
{ {
if (context.SelectedTreeNodes != null) { if (context.SelectedTreeNodes != null) {
ILSpyTreeNode[] nodes;
if (context.TreeView != MainWindow.Instance.treeView) { if (context.TreeView != MainWindow.Instance.treeView) {
nodes = context.SelectedTreeNodes.OfType<IMemberTreeNode>().Select(FindTreeNode).ToArray(); return context.SelectedTreeNodes.OfType<IMemberTreeNode>().Select(FindTreeNode).Where(n => n != null);
} else { } else {
nodes = context.SelectedTreeNodes.OfType<ILSpyTreeNode>().ToArray(); return context.SelectedTreeNodes.OfType<ILSpyTreeNode>().Where(n => n != null);
} }
DecompileNodes(nodes);
} else if (context.Reference?.Reference is IEntity entity) { } else if (context.Reference?.Reference is IEntity entity) {
if (MainWindow.Instance.FindTreeNode(entity) is ILSpyTreeNode node) { if (MainWindow.Instance.FindTreeNode(entity) is ILSpyTreeNode node) {
DecompileNodes(node); return new[] { node };
} }
} }
return Array.Empty<ILSpyTreeNode>();
ILSpyTreeNode FindTreeNode(IMemberTreeNode node) ILSpyTreeNode FindTreeNode(IMemberTreeNode node)
{ {
@ -64,7 +69,7 @@ namespace ICSharpCode.ILSpy.Commands
} }
} }
private static void DecompileNodes(params ILSpyTreeNode[] nodes) static void DecompileNodes(ILSpyTreeNode[] nodes)
{ {
if (nodes.Length == 0) if (nodes.Length == 0)
return; return;

Loading…
Cancel
Save