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

11
ILSpy/Commands/ScopeSearchToAssembly.cs

@ -15,6 +15,8 @@ @@ -15,6 +15,8 @@
// 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
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System;
using ICSharpCode.Decompiler.TypeSystem;
@ -28,7 +30,8 @@ namespace ICSharpCode.ILSpy @@ -28,7 +30,8 @@ namespace ICSharpCode.ILSpy
{
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[] args = NativeMethods.CommandLineToArgumentArray(searchTerm);
bool replaced = false;
@ -62,10 +65,10 @@ namespace ICSharpCode.ILSpy @@ -62,10 +65,10 @@ namespace ICSharpCode.ILSpy
return GetAssembly(context) != null;
}
string GetAssembly(TextViewContext context)
string? GetAssembly(TextViewContext context)
{
if (context.Reference?.Reference is IEntity entity)
return entity.ParentModule.AssemblyName;
return entity.ParentModule?.AssemblyName;
if (context.SelectedTreeNodes?.Length != 1)
return null;
switch (context.SelectedTreeNodes[0])
@ -73,7 +76,7 @@ namespace ICSharpCode.ILSpy @@ -73,7 +76,7 @@ namespace ICSharpCode.ILSpy
case AssemblyTreeNode tn:
return tn.LoadedAssembly.ShortName;
case IMemberTreeNode member:
return member.Member.ParentModule.AssemblyName;
return member.Member?.ParentModule?.AssemblyName;
default:
return null;
}

3
ILSpy/TreeNodes/IMemberTreeNode.cs

@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
// 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
// DEALINGS IN THE SOFTWARE.
#nullable enable
using ICSharpCode.Decompiler.TypeSystem;
@ -31,6 +32,6 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -31,6 +32,6 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// Returns the entity that is represented by this tree node.
/// May return null, if the member cannot be resolved.
/// </summary>
IEntity Member { get; }
IEntity? Member { get; }
}
}

Loading…
Cancel
Save