Fix NullReferenceException in ToolManager.IsAvailable and remove unnecessary try/catch.

This commit is contained in:
J.D. Purcell 2019-10-13 14:21:15 -04:00
parent eed94c11cc
commit 1ebdfa149a
2 changed files with 8 additions and 11 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace BizHawk.Client.EmuHawk
{
@ -9,14 +10,14 @@ namespace BizHawk.Client.EmuHawk
public ToolAttribute(bool released, string[] supportedSystems, string[] unsupportedCores = null)
{
Released = released;
SupportedSystems = supportedSystems;
UnsupportedCores = unsupportedCores;
SupportedSystems = supportedSystems ?? Enumerable.Empty<string>();
UnsupportedCores = unsupportedCores ?? Enumerable.Empty<string>();
}
public bool Released { get; private set; }
public bool Released { get; }
public IEnumerable<string> SupportedSystems { get; private set; }
public IEnumerable<string> SupportedSystems { get; }
public IEnumerable<string> UnsupportedCores { get; private set; }
public IEnumerable<string> UnsupportedCores { get; }
}
}

View File

@ -752,12 +752,8 @@ namespace BizHawk.Client.EmuHawk
return false;
}
ToolAttribute attr;
try
{
attr = tool.GetCustomAttributes(false).OfType<ToolAttribute>().Single();
}
catch (InvalidOperationException e)
ToolAttribute attr = tool.GetCustomAttributes(false).OfType<ToolAttribute>().SingleOrDefault();
if (attr == null)
{
return true; // no ToolAttribute on given type -> assumed all supported
}