Browse Source

Fix nullability warnings in ILSpyX

pull/2828/head
Daniel Grunwald 3 years ago
parent
commit
3b6a650cf1
  1. 1
      ICSharpCode.ILSpyX/ICSharpCode.ILSpyX.csproj
  2. 7
      ICSharpCode.ILSpyX/Search/AbstractEntitySearchStrategy.cs
  3. 20
      ICSharpCode.ILSpyX/Search/AssemblySearchStrategy.cs
  4. 2
      ICSharpCode.ILSpyX/Search/CSharpLexer.cs
  5. 11
      ICSharpCode.ILSpyX/Search/LiteralSearchStrategy.cs
  6. 12
      ICSharpCode.ILSpyX/Search/SearchResult.cs

1
ICSharpCode.ILSpyX/ICSharpCode.ILSpyX.csproj

@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<WarningsAsErrors>nullable</WarningsAsErrors>
<SignAssembly>True</SignAssembly> <SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.snk</AssemblyOriginatorKeyFile>

7
ICSharpCode.ILSpyX/Search/AbstractEntitySearchStrategy.cs

@ -37,12 +37,12 @@ namespace ICSharpCode.ILSpyX.Search
this.apiVisibility = apiVisibility; this.apiVisibility = apiVisibility;
} }
protected bool CheckVisibility(IEntity entity) protected bool CheckVisibility(IEntity? entity)
{ {
if (apiVisibility == ApiVisibility.All) if (apiVisibility == ApiVisibility.All)
return true; return true;
do while (entity != null)
{ {
if (apiVisibility == ApiVisibility.PublicOnly) if (apiVisibility == ApiVisibility.PublicOnly)
{ {
@ -58,7 +58,6 @@ namespace ICSharpCode.ILSpyX.Search
} }
entity = entity.DeclaringTypeDefinition; entity = entity.DeclaringTypeDefinition;
} }
while (entity != null);
return true; return true;
} }
@ -67,7 +66,7 @@ namespace ICSharpCode.ILSpyX.Search
{ {
if (searchRequest.InAssembly != null) if (searchRequest.InAssembly != null)
{ {
if (!entity.ParentModule.FullAssemblyName.Contains(searchRequest.InAssembly)) if (entity.ParentModule == null || !entity.ParentModule.FullAssemblyName.Contains(searchRequest.InAssembly))
{ {
return false; return false;
} }

20
ICSharpCode.ILSpyX/Search/AssemblySearchStrategy.cs

@ -41,19 +41,27 @@ namespace ICSharpCode.ILSpyX.Search
if (searchKind == AssemblySearchKind.NameOrFileName) if (searchKind == AssemblySearchKind.NameOrFileName)
{ {
string localName = GetNameToMatch(module, AssemblySearchKind.Name); string? localName = GetNameToMatch(module, AssemblySearchKind.Name);
string fileName = Path.GetFileName(GetNameToMatch(module, AssemblySearchKind.FilePath)); string? filePath = GetNameToMatch(module, AssemblySearchKind.FilePath);
if (IsMatch(localName) || IsMatch(fileName)) if (localName != null && IsMatch(localName))
{
OnFoundResult(module); OnFoundResult(module);
}
else if (filePath != null)
{
string fileName = Path.GetFileName(filePath);
if (IsMatch(fileName))
OnFoundResult(module);
}
return; return;
} }
string name = GetNameToMatch(module, searchKind); string? name = GetNameToMatch(module, searchKind);
if (IsMatch(name)) if (name != null && IsMatch(name))
OnFoundResult(module); OnFoundResult(module);
} }
string GetNameToMatch(PEFile module, AssemblySearchKind kind) string? GetNameToMatch(PEFile module, AssemblySearchKind kind)
{ {
switch (kind) switch (kind)
{ {

2
ICSharpCode.ILSpyX/Search/CSharpLexer.cs

@ -16,6 +16,8 @@
// 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 disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;

11
ICSharpCode.ILSpyX/Search/LiteralSearchStrategy.cs

@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Diagnostics;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Threading; using System.Threading;
@ -35,8 +36,8 @@ namespace ICSharpCode.ILSpyX.Search
{ {
public class LiteralSearchStrategy : AbstractEntitySearchStrategy public class LiteralSearchStrategy : AbstractEntitySearchStrategy
{ {
readonly TypeCode searchTermLiteralType; readonly TypeCode searchTermLiteralType = TypeCode.Empty;
readonly object searchTermLiteralValue; readonly object? searchTermLiteralValue;
public LiteralSearchStrategy(ILanguage language, ApiVisibility apiVisibility, SearchRequest request, public LiteralSearchStrategy(ILanguage language, ApiVisibility apiVisibility, SearchRequest request,
IProducerConsumerCollection<SearchResult> resultQueue) IProducerConsumerCollection<SearchResult> resultQueue)
@ -131,10 +132,12 @@ namespace ICSharpCode.ILSpyX.Search
case TypeCode.Single: case TypeCode.Single:
case TypeCode.Double: case TypeCode.Double:
case TypeCode.String: case TypeCode.String:
Debug.Assert(searchTermLiteralValue != null);
return searchTermLiteralValue.Equals(val); return searchTermLiteralValue.Equals(val);
default: default:
// substring search with searchTerm // substring search with searchTerm
return IsMatch(val.ToString()); string? valAsString = val.ToString();
return valAsString != null && IsMatch(valAsString);
} }
} }
@ -143,6 +146,7 @@ namespace ICSharpCode.ILSpyX.Search
var blob = module.Reader.GetMethodBody(methodDefinition.RelativeVirtualAddress).GetILReader(); var blob = module.Reader.GetMethodBody(methodDefinition.RelativeVirtualAddress).GetILReader();
if (searchTermLiteralType == TypeCode.Int64) if (searchTermLiteralType == TypeCode.Int64)
{ {
Debug.Assert(searchTermLiteralValue != null);
long val = (long)searchTermLiteralValue; long val = (long)searchTermLiteralValue;
while (blob.RemainingBytes > 0) while (blob.RemainingBytes > 0)
{ {
@ -209,6 +213,7 @@ namespace ICSharpCode.ILSpyX.Search
} }
else if (searchTermLiteralType != TypeCode.Empty) else if (searchTermLiteralType != TypeCode.Empty)
{ {
Debug.Assert(searchTermLiteralValue != null);
ILOpCode expectedCode; ILOpCode expectedCode;
switch (searchTermLiteralType) switch (searchTermLiteralType)
{ {

12
ICSharpCode.ILSpyX/Search/SearchResult.cs

@ -42,14 +42,18 @@ namespace ICSharpCode.ILSpyX.Search
public float Fitness { get; set; } public float Fitness { get; set; }
#nullable disable
public string Name { get; set; } public string Name { get; set; }
public string Location { get; set; } public string Location { get; set; }
public string Assembly { get; set; } public string Assembly { get; set; }
#nullable enable
public object? ToolTip { get; set; } public object? ToolTip { get; set; }
#nullable disable
public object Image { get; set; } public object Image { get; set; }
public object LocationImage { get; set; } public object LocationImage { get; set; }
public object AssemblyImage { get; set; } public object AssemblyImage { get; set; }
#nullable enable
public override string ToString() public override string ToString()
{ {
@ -76,25 +80,33 @@ namespace ICSharpCode.ILSpyX.Search
public class MemberSearchResult : SearchResult public class MemberSearchResult : SearchResult
{ {
#nullable disable
public IEntity Member { get; set; } public IEntity Member { get; set; }
public override object Reference => Member; public override object Reference => Member;
#nullable enable
} }
public class ResourceSearchResult : SearchResult public class ResourceSearchResult : SearchResult
{ {
#nullable disable
public Resource Resource { get; set; } public Resource Resource { get; set; }
#nullable enable
public override object Reference => ValueTuple.Create(Resource, Name); public override object Reference => ValueTuple.Create(Resource, Name);
} }
public class AssemblySearchResult : SearchResult public class AssemblySearchResult : SearchResult
{ {
#nullable disable
public PEFile Module { get; set; } public PEFile Module { get; set; }
public override object Reference => Module; public override object Reference => Module;
#nullable enable
} }
public class NamespaceSearchResult : SearchResult public class NamespaceSearchResult : SearchResult
{ {
#nullable disable
public INamespace Namespace { get; set; } public INamespace Namespace { get; set; }
public override object Reference => Namespace; public override object Reference => Namespace;
#nullable enable
} }
} }
Loading…
Cancel
Save