Reduce implicit null checks

This commit is contained in:
Matt Nadareski
2023-08-10 11:35:32 -04:00
parent 5213490689
commit c59bd4d857
35 changed files with 1406 additions and 783 deletions

View File

@@ -273,7 +273,7 @@ namespace SabreTools.DatFiles.Formats
ConvertDeviceRefs(game.DeviceRef, machine, filename, indexId, statsOnly, ref containsItems);
ConvertSamples(game.Sample, machine, filename, indexId, statsOnly, ref containsItems);
ConvertArchives(game.Archive, machine, filename, indexId, statsOnly, ref containsItems);
ConvertDrivers(game.Driver, machine, filename, indexId, statsOnly, ref containsItems);
ConvertDriver(game.Driver, machine, filename, indexId, statsOnly, ref containsItems);
ConvertSoftwareLists(game.SoftwareList, machine, filename, indexId, statsOnly, ref containsItems);
// If we had no items, create a Blank placeholder
@@ -599,42 +599,39 @@ namespace SabreTools.DatFiles.Formats
/// <summary>
/// Convert Driver information
/// </summary>
/// <param name="drivers">Array of deserialized models to convert</param>
/// <param name="driver">Deserialized model to convert</param>
/// <param name="machine">Prefilled machine to use</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
/// <param name="containsItems">True if there were any items in the array, false otherwise</param>
private void ConvertDrivers(Models.Logiqx.Driver[]? drivers, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
private void ConvertDriver(Models.Logiqx.Driver? driver, Machine machine, string filename, int indexId, bool statsOnly, ref bool containsItems)
{
// If the drivers array is missing, we can't do anything
if (drivers == null || !drivers.Any())
// If the driver is missing, we can't do anything
if (driver == null)
return;
containsItems = true;
foreach (var driver in drivers)
var item = new Driver
{
var item = new Driver
Status = driver.Status?.AsSupportStatus() ?? SupportStatus.NULL,
Emulation = driver.Emulation?.AsSupportStatus() ?? SupportStatus.NULL,
Cocktail = driver.Cocktail?.AsSupportStatus() ?? SupportStatus.NULL,
SaveState = driver.SaveState?.AsSupported() ?? Supported.NULL,
RequiresArtwork = driver.RequiresArtwork?.AsYesNo(),
Unofficial = driver.Unofficial?.AsYesNo(),
NoSoundHardware = driver.NoSoundHardware?.AsYesNo(),
Incomplete = driver.Incomplete?.AsYesNo(),
Source = new Source
{
Status = driver.Status?.AsSupportStatus() ?? SupportStatus.NULL,
Emulation = driver.Emulation?.AsSupportStatus() ?? SupportStatus.NULL,
Cocktail = driver.Cocktail?.AsSupportStatus() ?? SupportStatus.NULL,
SaveState = driver.SaveState?.AsSupported() ?? Supported.NULL,
RequiresArtwork = driver.RequiresArtwork?.AsYesNo(),
Unofficial = driver.Unofficial?.AsYesNo(),
NoSoundHardware = driver.NoSoundHardware?.AsYesNo(),
Incomplete = driver.Incomplete?.AsYesNo(),
Index = indexId,
Name = filename,
},
};
Source = new Source
{
Index = indexId,
Name = filename,
},
};
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
}
item.CopyMachineInformation(machine);
ParseAddHelper(item, statsOnly);
}
/// <summary>

View File

@@ -314,7 +314,6 @@ namespace SabreTools.DatFiles.Formats
var samples = new List<Models.Logiqx.Sample>();
var archives = new List<Models.Logiqx.Archive>();
var devicerefs = new List<Models.Logiqx.DeviceRef>();
var drivers = new List<Models.Logiqx.Driver>();
var softwarelists = new List<Models.Logiqx.SoftwareList>();
// Loop through and convert the items to respective lists
@@ -357,7 +356,7 @@ namespace SabreTools.DatFiles.Formats
devicerefs.Add(CreateDeviceRef(deviceref));
break;
case Driver driver:
drivers.Add(CreateDriver(driver));
game.Driver = CreateDriver(driver);
break;
case DatItems.Formats.SoftwareList softwarelist:
softwarelists.Add(CreateSoftwareList(softwarelist));
@@ -374,7 +373,6 @@ namespace SabreTools.DatFiles.Formats
game.Sample = samples.ToArray();
game.Archive = archives.ToArray();
game.DeviceRef = devicerefs.ToArray();
game.Driver = drivers.ToArray();
game.SoftwareList = softwarelists.ToArray();
// Add the game to the list