Browse Source

Fix #2664: Fix NRE in ScopeSearchToAssembly.

pull/2667/head
Siegfried Pammer 3 years ago
parent
commit
aafa9b2aa7
  1. 3
      ICSharpCode.Decompiler/TypeSystem/IEntity.cs
  2. 11
      ILSpy/Commands/ScopeSearchToAssembly.cs
  3. 3
      ILSpy/TreeNodes/IMemberTreeNode.cs

3
ICSharpCode.Decompiler/TypeSystem/IEntity.cs

@ -58,8 +58,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <summary> /// <summary>
/// The module in which this entity is defined. /// The module in which this entity is defined.
/// May return null, if the IEntity was not created from a module.
/// </summary> /// </summary>
IModule ParentModule { get; } IModule? ParentModule { get; }
/// <summary> /// <summary>
/// Gets the attributes on this entity. /// Gets the attributes on this entity.

11
ILSpy/Commands/ScopeSearchToAssembly.cs

@ -15,6 +15,8 @@
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// 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.
#nullable enable
using System; using System;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
@ -28,7 +30,8 @@ namespace ICSharpCode.ILSpy
{ {
public void Execute(TextViewContext context) public void Execute(TextViewContext context)
{ {
string asmName = GetAssembly(context); // asmName cannot be null here, because Execute is only called if IsEnabled/IsVisible return true.
string asmName = GetAssembly(context)!;
string searchTerm = MainWindow.Instance.SearchPane.SearchTerm; string searchTerm = MainWindow.Instance.SearchPane.SearchTerm;
string[] args = NativeMethods.CommandLineToArgumentArray(searchTerm); string[] args = NativeMethods.CommandLineToArgumentArray(searchTerm);
bool replaced = false; bool replaced = false;
@ -62,10 +65,10 @@ namespace ICSharpCode.ILSpy
return GetAssembly(context) != null; return GetAssembly(context) != null;
} }
string GetAssembly(TextViewContext context) string? GetAssembly(TextViewContext context)
{ {
if (context.Reference?.Reference is IEntity entity) if (context.Reference?.Reference is IEntity entity)
return entity.ParentModule.AssemblyName; return entity.ParentModule?.AssemblyName;
if (context.SelectedTreeNodes?.Length != 1) if (context.SelectedTreeNodes?.Length != 1)
return null; return null;
switch (context.SelectedTreeNodes[0]) switch (context.SelectedTreeNodes[0])
@ -73,7 +76,7 @@ namespace ICSharpCode.ILSpy
case AssemblyTreeNode tn: case AssemblyTreeNode tn:
return tn.LoadedAssembly.ShortName; return tn.LoadedAssembly.ShortName;
case IMemberTreeNode member: case IMemberTreeNode member:
return member.Member.ParentModule.AssemblyName; return member.Member?.ParentModule?.AssemblyName;
default: default:
return null; return null;
} }

3
ILSpy/TreeNodes/IMemberTreeNode.cs

@ -15,6 +15,7 @@
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// 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.
#nullable enable
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
@ -31,6 +32,6 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// Returns the entity that is represented by this tree node. /// Returns the entity that is represented by this tree node.
/// May return null, if the member cannot be resolved. /// May return null, if the member cannot be resolved.
/// </summary> /// </summary>
IEntity Member { get; } IEntity? Member { get; }
} }
} }

Loading…
Cancel
Save