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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
@ -9,14 +10,14 @@ namespace BizHawk.Client.EmuHawk
public ToolAttribute(bool released, string[] supportedSystems, string[] unsupportedCores = null) public ToolAttribute(bool released, string[] supportedSystems, string[] unsupportedCores = null)
{ {
Released = released; Released = released;
SupportedSystems = supportedSystems; SupportedSystems = supportedSystems ?? Enumerable.Empty<string>();
UnsupportedCores = unsupportedCores; 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; return false;
} }
ToolAttribute attr; ToolAttribute attr = tool.GetCustomAttributes(false).OfType<ToolAttribute>().SingleOrDefault();
try if (attr == null)
{
attr = tool.GetCustomAttributes(false).OfType<ToolAttribute>().Single();
}
catch (InvalidOperationException e)
{ {
return true; // no ToolAttribute on given type -> assumed all supported return true; // no ToolAttribute on given type -> assumed all supported
} }