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

7
ICSharpCode.ILSpyX/Search/AbstractEntitySearchStrategy.cs

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

20
ICSharpCode.ILSpyX/Search/AssemblySearchStrategy.cs

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

2
ICSharpCode.ILSpyX/Search/CSharpLexer.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable disable
using System;
using System.Collections.Generic;
using System.Globalization;

11
ICSharpCode.ILSpyX/Search/LiteralSearchStrategy.cs

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

12
ICSharpCode.ILSpyX/Search/SearchResult.cs

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