Enable nullability everywhere

This commit is contained in:
Matt Nadareski
2024-02-28 19:19:50 -05:00
parent 11d024bd16
commit 823a9ca7b7
145 changed files with 1545 additions and 1260 deletions

View File

@@ -31,7 +31,7 @@ namespace SabreTools.DatFiles
/// DatItems and related statistics
/// </summary>
[JsonProperty("items"), XmlElement("items")]
public ItemDictionary Items { get; set; } = new ItemDictionary();
public ItemDictionary Items { get; set; } = [];
#endregion
@@ -511,7 +511,7 @@ namespace SabreTools.DatFiles
/// <returns>List of supported types for writing</returns>
protected virtual ItemType[] GetSupportedTypes()
{
return Enum.GetValues(typeof(ItemType)) as ItemType[] ?? Array.Empty<ItemType>();
return Enum.GetValues(typeof(ItemType)) as ItemType[] ?? [];
}
/// <summary>

View File

@@ -2,11 +2,10 @@
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Core;
using SabreTools.Core.Tools;
using SabreTools.DatFiles.Formats;
using Newtonsoft.Json;
namespace SabreTools.DatFiles
{
@@ -744,14 +743,14 @@ namespace SabreTools.DatFiles
public Dictionary<DatFormat, string> CreateOutFileNames(string outDir, bool overwrite = true)
{
// Create the output dictionary
Dictionary<DatFormat, string> outfileNames = new();
Dictionary<DatFormat, string> outfileNames = [];
// Double check the outDir for the end delim
if (!outDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
outDir += Path.DirectorySeparatorChar;
// Get all used extensions
List<string> usedExtensions = new();
List<string> usedExtensions = [];
// Get the extensions from the output type

View File

@@ -15,16 +15,16 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[]
{
return
[
ItemType.Rom,
};
];
}
/// <inheritdoc/>
protected override List<DatItemField>? GetMissingRequiredFields(DatItem datItem)
{
List<DatItemField> missingFields = new();
List<DatItemField> missingFields = [];
// Check item name
if (string.IsNullOrWhiteSpace(datItem.GetName()))
@@ -115,7 +115,7 @@ namespace SabreTools.DatFiles.Formats
}
}
return new Models.ArchiveDotOrg.Files { File = files.ToArray() };
return new Models.ArchiveDotOrg.Files { File = [.. files] };
}
/// <summary>

View File

@@ -15,13 +15,16 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[] { ItemType.Rom };
return
[
ItemType.Rom
];
}
/// <inheritdoc/>
protected override List<DatItemField>? GetMissingRequiredFields(DatItem datItem)
{
List<DatItemField> missingFields = new();
List<DatItemField> missingFields = [];
// Check item name
if (string.IsNullOrWhiteSpace(datItem.GetName()))
@@ -111,7 +114,7 @@ namespace SabreTools.DatFiles.Formats
}
}
return rows.ToArray();
return [.. rows];
}
/// <summary>

View File

@@ -528,13 +528,13 @@ namespace SabreTools.DatFiles.Formats
{
Players = NumberHelper.ConvertToInt64(input.Players),
//Control = input.Control, // TODO: Add to internal model or find mapping
Controls = new List<Control>
{
Controls =
[
new Control
{
Buttons = NumberHelper.ConvertToInt64(input.Buttons),
},
},
],
Coins = NumberHelper.ConvertToInt64(input.Coins),
Tilt = input.Tilt?.AsYesNo(),
Service = input.Service?.AsYesNo(),
@@ -571,7 +571,7 @@ namespace SabreTools.DatFiles.Formats
var item = new DipSwitch
{
Name = dipswitch.Name,
Values = new List<DipValue>(),
Values = [],
Source = new Source
{
@@ -580,7 +580,7 @@ namespace SabreTools.DatFiles.Formats
},
};
foreach (string entry in dipswitch.Entry ?? Array.Empty<string>())
foreach (string entry in dipswitch.Entry ?? [])
{
var dipValue = new DipValue
{

View File

@@ -16,8 +16,8 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[]
{
return
[
ItemType.Archive,
ItemType.BiosSet,
ItemType.Chip,
@@ -31,7 +31,7 @@ namespace SabreTools.DatFiles.Formats
ItemType.Rom,
ItemType.Sample,
ItemType.Sound,
};
];
}
/// <inheritdoc/>
@@ -312,22 +312,22 @@ namespace SabreTools.DatFiles.Formats
}
// Assign the values to the game
game.Release = releases.ToArray();
game.BiosSet = biossets.ToArray();
game.Rom = roms.ToArray();
game.Disk = disks.ToArray();
game.Media = medias.ToArray();
game.Sample = samples.ToArray();
game.Archive = archives.ToArray();
game.Chip = chips.ToArray();
game.Video = videos.ToArray();
game.DipSwitch = dipswitches.ToArray();
game.Release = [.. releases];
game.BiosSet = [.. biossets];
game.Rom = [.. roms];
game.Disk = [.. disks];
game.Media = [.. medias];
game.Sample = [.. samples];
game.Archive = [.. archives];
game.Chip = [.. chips];
game.Video = [.. videos];
game.DipSwitch = [.. dipswitches];
// Add the game to the list
games.Add(game);
}
return games.ToArray();
return [.. games];
}
/// <summary>
@@ -560,7 +560,7 @@ namespace SabreTools.DatFiles.Formats
dipswitch.Default = setting.Value;
}
dipswitch.Entry = entries.ToArray();
dipswitch.Entry = [.. entries];
}
return dipswitch;

View File

@@ -15,16 +15,16 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[]
{
return
[
ItemType.Rom
};
];
}
/// <inheritdoc/>
protected override List<DatItemField>? GetMissingRequiredFields(DatItem datItem)
{
List<DatItemField> missingFields = new();
List<DatItemField> missingFields = [];
// Check item name
if (string.IsNullOrWhiteSpace(datItem.GetName()))
@@ -162,13 +162,13 @@ namespace SabreTools.DatFiles.Formats
}
// Assign the values to the game
game.File = files.ToArray();
game.File = [.. files];
// Add the game to the list
games.Add(game);
}
return games.ToArray();
return [.. games];
}
/// <summary>

View File

@@ -15,16 +15,16 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[]
{
return
[
ItemType.Rom
};
];
}
/// <inheritdoc/>
protected override List<DatItemField>? GetMissingRequiredFields(DatItem datItem)
{
List<DatItemField> missingFields = new();
List<DatItemField> missingFields = [];
// Check item name
if (string.IsNullOrWhiteSpace(datItem.GetName()))
@@ -128,7 +128,7 @@ namespace SabreTools.DatFiles.Formats
}
}
return rows.ToArray();
return [.. rows];
}
/// <summary>

View File

@@ -16,18 +16,18 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[]
{
return
[
ItemType.Disk,
ItemType.Media,
ItemType.Rom
};
];
}
/// <inheritdoc/>
protected override List<DatItemField>? GetMissingRequiredFields(DatItem datItem)
{
List<DatItemField> missingFields = new();
List<DatItemField> missingFields = [];
// Check item name
if (string.IsNullOrWhiteSpace(datItem.GetName()))
@@ -259,7 +259,7 @@ namespace SabreTools.DatFiles.Formats
}
}
return sfvs.ToArray();
return [.. sfvs];
}
/// <summary>
@@ -326,7 +326,7 @@ namespace SabreTools.DatFiles.Formats
}
}
return md5s.ToArray();
return [.. md5s];
}
/// <summary>
@@ -393,7 +393,7 @@ namespace SabreTools.DatFiles.Formats
}
}
return sha1s.ToArray();
return [.. sha1s];
}
/// <summary>
@@ -452,7 +452,7 @@ namespace SabreTools.DatFiles.Formats
}
}
return sha256s.ToArray();
return [.. sha256s];
}
/// <summary>
@@ -503,7 +503,7 @@ namespace SabreTools.DatFiles.Formats
}
}
return sha384s.ToArray();
return [.. sha384s];
}
/// <summary>
@@ -554,7 +554,7 @@ namespace SabreTools.DatFiles.Formats
}
}
return sha512s.ToArray();
return [.. sha512s];
}
/// <summary>
@@ -613,7 +613,7 @@ namespace SabreTools.DatFiles.Formats
}
}
return spamsums.ToArray();
return [.. spamsums];
}
#endregion

View File

@@ -24,7 +24,7 @@ namespace SabreTools.DatFiles.Formats
/// <summary>
/// Convert hash types between internal and Serialization
/// </summary>
private Serialization.Hash ConvertHash(Hash hash)
private static Serialization.Hash ConvertHash(Hash hash)
{
return hash switch
{
@@ -35,7 +35,7 @@ namespace SabreTools.DatFiles.Formats
Hash.SHA384 => Serialization.Hash.SHA384,
Hash.SHA512 => Serialization.Hash.SHA512,
Hash.SpamSum => Serialization.Hash.SpamSum,
_ => throw new System.ArgumentOutOfRangeException(),
_ => throw new System.ArgumentOutOfRangeException(nameof(hash)),
};
}
}

View File

@@ -88,7 +88,7 @@ namespace SabreTools.DatFiles.Formats
return;
}
foreach (var row in set.Row ?? Array.Empty<Models.Listrom.Row>())
foreach (var row in set.Row ?? [])
{
ConvertRow(row, machine, filename, indexId, statsOnly);
}

View File

@@ -15,17 +15,17 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[]
{
return
[
ItemType.Disk,
ItemType.Rom
};
];
}
/// <inheritdoc/>
protected override List<DatItemField>? GetMissingRequiredFields(DatItem datItem)
{
List<DatItemField> missingFields = new();
List<DatItemField> missingFields = [];
// Check item name
if (string.IsNullOrWhiteSpace(datItem.GetName()))
@@ -148,12 +148,12 @@ namespace SabreTools.DatFiles.Formats
}
}
set.Row = rows.ToArray();
set.Row = [.. rows];
sets.Add(set);
rows.Clear();
}
return sets.ToArray();
return [.. sets];
}
/// <summary>

View File

@@ -545,7 +545,7 @@ namespace SabreTools.DatFiles.Formats
};
var controls = new List<Control>();
foreach (var control in input.Control ?? Array.Empty<Models.Listxml.Control>())
foreach (var control in input.Control ?? [])
{
var controlItem = new Control
{
@@ -612,11 +612,11 @@ namespace SabreTools.DatFiles.Formats
Relation = dipswitch.Condition.Relation.AsRelation(),
Value = dipswitch.Condition.Value,
};
item.Conditions = new List<Condition> { condition };
item.Conditions = [condition];
}
var locations = new List<DipLocation>();
foreach (var diplocation in dipswitch.DipLocation ?? Array.Empty<Models.Listxml.DipLocation>())
foreach (var diplocation in dipswitch.DipLocation ?? [])
{
var locationItem = new DipLocation
{
@@ -631,7 +631,7 @@ namespace SabreTools.DatFiles.Formats
item.Locations = locations;
var settings = new List<DipValue>();
foreach (var dipvalue in dipswitch.DipValue ?? Array.Empty<Models.Listxml.DipValue>())
foreach (var dipvalue in dipswitch.DipValue ?? [])
{
var dipValueItem = new DipValue
{
@@ -649,7 +649,7 @@ namespace SabreTools.DatFiles.Formats
Relation = dipvalue.Condition.Relation.AsRelation(),
Value = dipvalue.Condition.Value,
};
dipValueItem.Conditions = new List<Condition> { condition };
dipValueItem.Conditions = [condition];
}
settings.Add(dipValueItem);
@@ -703,11 +703,11 @@ namespace SabreTools.DatFiles.Formats
Relation = configuration.Condition.Relation.AsRelation(),
Value = configuration.Condition.Value,
};
item.Conditions = new List<DatItems.Formats.Condition> { condition };
item.Conditions = [condition];
}
var locations = new List<ConfLocation>();
foreach (var confLocation in configuration.ConfLocation ?? Array.Empty<Models.Listxml.ConfLocation>())
foreach (var confLocation in configuration.ConfLocation ?? [])
{
var locationItem = new ConfLocation
{
@@ -722,7 +722,7 @@ namespace SabreTools.DatFiles.Formats
item.Locations = locations;
var settings = new List<ConfSetting>();
foreach (var dipvalue in configuration.ConfSetting ?? Array.Empty<Models.Listxml.ConfSetting>())
foreach (var dipvalue in configuration.ConfSetting ?? [])
{
var settingItem = new ConfSetting
{
@@ -740,7 +740,7 @@ namespace SabreTools.DatFiles.Formats
Relation = dipvalue.Condition.Relation.AsRelation(),
Value = dipvalue.Condition.Value,
};
settingItem.Conditions = new List<Condition> { condition };
settingItem.Conditions = [condition];
}
settings.Add(settingItem);
@@ -784,7 +784,7 @@ namespace SabreTools.DatFiles.Formats
};
var analogs = new List<Analog>();
foreach (var analog in port.Analog ?? Array.Empty<Models.Listxml.Analog>())
foreach (var analog in port.Analog ?? [])
{
var analogItem = new Analog
{
@@ -840,7 +840,7 @@ namespace SabreTools.DatFiles.Formats
Relation = adjuster.Condition.Relation.AsRelation(),
Value = adjuster.Condition.Value,
};
item.Conditions = new List<Condition> { condition };
item.Conditions = [condition];
}
item.CopyMachineInformation(machine);
@@ -965,11 +965,11 @@ namespace SabreTools.DatFiles.Formats
Name = device.Instance.Name,
BriefName = device.Instance.BriefName,
};
item.Instances = new List<Instance> { instance };
item.Instances = [instance];
}
var extensions = new List<Extension>();
foreach (var extension in device.Extension ?? Array.Empty<Models.Listxml.Extension>())
foreach (var extension in device.Extension ?? [])
{
var extensionItem = new Extension
{
@@ -1016,7 +1016,7 @@ namespace SabreTools.DatFiles.Formats
};
var slotoptions = new List<SlotOption>();
foreach (var slotoption in slot.SlotOption ?? Array.Empty<Models.Listxml.SlotOption>())
foreach (var slotoption in slot.SlotOption ?? [])
{
var slotoptionItem = new SlotOption
{

View File

@@ -16,8 +16,8 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[]
{
return
[
ItemType.Adjuster,
ItemType.BiosSet,
ItemType.Chip,
@@ -38,7 +38,7 @@ namespace SabreTools.DatFiles.Formats
ItemType.Slot,
ItemType.SoftwareList,
ItemType.Sound,
};
];
}
/// <inheritdoc/>
@@ -244,7 +244,7 @@ namespace SabreTools.DatFiles.Formats
// Get the first item for game information
var machine = items[0].Machine;
var game = CreateGame(machine!);
var game = Listxml.CreateGame(machine!);
// Create holders for all item types
var biosSets = new List<Models.Listxml.BiosSet>();
@@ -340,35 +340,35 @@ namespace SabreTools.DatFiles.Formats
}
// Assign the values to the game
game.BiosSet = biosSets.ToArray();
game.Rom = roms.ToArray();
game.Disk = disks.ToArray();
game.DeviceRef = deviceRefs.ToArray();
game.Sample = samples.ToArray();
game.Chip = chips.ToArray();
game.Display = displays.ToArray();
game.BiosSet = [.. biosSets];
game.Rom = [.. roms];
game.Disk = [.. disks];
game.DeviceRef = [.. deviceRefs];
game.Sample = [.. samples];
game.Chip = [.. chips];
game.Display = [.. displays];
game.Video = null;
game.DipSwitch = dipSwitches.ToArray();
game.Configuration = configurations.ToArray();
game.Port = ports.ToArray();
game.Adjuster = adjusters.ToArray();
game.Feature = features.ToArray();
game.Device = devices.ToArray();
game.Slot = slots.ToArray();
game.SoftwareList = softwareLists.ToArray();
game.RamOption = ramOptions.ToArray();
game.DipSwitch = [.. dipSwitches];
game.Configuration = [.. configurations];
game.Port = [.. ports];
game.Adjuster = [.. adjusters];
game.Feature = [.. features];
game.Device = [.. devices];
game.Slot = [.. slots];
game.SoftwareList = [.. softwareLists];
game.RamOption = [.. ramOptions];
// Add the game to the list
games.Add(game);
}
return games.ToArray();
return [.. games];
}
/// <summary>
/// Create a GameBase from the current internal information
/// <summary>
private Models.Listxml.GameBase CreateGame(Machine machine)
private static Models.Listxml.GameBase CreateGame(Machine machine)
{
var game = new Models.Listxml.Machine
{
@@ -554,14 +554,14 @@ namespace SabreTools.DatFiles.Formats
};
var controls = new List<Models.Listxml.Control>();
foreach (var controlItem in item.Controls ?? new List<Control>())
foreach (var controlItem in item.Controls ?? [])
{
var control = CreateControl(controlItem);
controls.Add(control);
}
if (controls.Any())
input.Control = controls.ToArray();
input.Control = [.. controls];
return input;
}
@@ -616,24 +616,24 @@ namespace SabreTools.DatFiles.Formats
}
var diplocations = new List<Models.Listxml.DipLocation>();
foreach (var locationItem in item.Locations ?? new List<DipLocation>())
foreach (var locationItem in item.Locations ?? [])
{
var control = CreateDipLocation(locationItem);
diplocations.Add(control);
}
if (diplocations.Any())
dipswitch.DipLocation = diplocations.ToArray();
dipswitch.DipLocation = [.. diplocations];
var dipvalues = new List<Models.Listxml.DipValue>();
foreach (var dipValueItem in item.Values ?? new List<DipValue>())
foreach (var dipValueItem in item.Values ?? [])
{
var dipvalue = CreateDipValue(dipValueItem);
dipvalues.Add(dipvalue);
}
if (dipvalues.Any())
dipswitch.DipValue = dipvalues.ToArray();
dipswitch.DipValue = [.. dipvalues];
return dipswitch;
}
@@ -707,24 +707,24 @@ namespace SabreTools.DatFiles.Formats
}
var confLocations = new List<Models.Listxml.ConfLocation>();
foreach (var location in item.Locations ?? new List<ConfLocation>())
foreach (var location in item.Locations ?? [])
{
var control = CreateConfLocation(location);
confLocations.Add(control);
}
if (confLocations.Any())
configuration.ConfLocation = confLocations.ToArray();
configuration.ConfLocation = [.. confLocations];
var confsettings = new List<Models.Listxml.ConfSetting>();
foreach (var confSettingItem in item.Settings ?? new List<ConfSetting>())
foreach (var confSettingItem in item.Settings ?? [])
{
var dipvalue = CreateConfSetting(confSettingItem);
confsettings.Add(dipvalue);
}
if (confsettings.Any())
configuration.ConfSetting = confsettings.ToArray();
configuration.ConfSetting = [.. confsettings];
return configuration;
}
@@ -876,7 +876,7 @@ namespace SabreTools.DatFiles.Formats
}
var extensions = new List<Models.Listxml.Extension>();
foreach (var extensionItem in item.Extensions ?? new List<Extension>())
foreach (var extensionItem in item.Extensions ?? [])
{
var extension = new Models.Listxml.Extension
{
@@ -886,7 +886,7 @@ namespace SabreTools.DatFiles.Formats
}
if (extensions.Any())
device.Extension = extensions.ToArray();
device.Extension = [.. extensions];
return device;
}
@@ -902,7 +902,7 @@ namespace SabreTools.DatFiles.Formats
};
var slotoptions = new List<Models.Listxml.SlotOption>();
foreach (var slotoptionItem in item.SlotOptions ?? new List<SlotOption>())
foreach (var slotoptionItem in item.SlotOptions ?? [])
{
var slotoption = new Models.Listxml.SlotOption
{
@@ -914,7 +914,7 @@ namespace SabreTools.DatFiles.Formats
}
if (slotoptions.Any())
slot.SlotOption = slotoptions.ToArray();
slot.SlotOption = [.. slotoptions];
return slot;
}

View File

@@ -16,8 +16,8 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[]
{
return
[
ItemType.Archive,
ItemType.BiosSet,
ItemType.Disk,
@@ -25,7 +25,7 @@ namespace SabreTools.DatFiles.Formats
ItemType.Release,
ItemType.Rom,
ItemType.Sample,
};
];
}
/// <inheritdoc/>
@@ -365,21 +365,21 @@ namespace SabreTools.DatFiles.Formats
}
// Assign the values to the game
game.Release = releases.ToArray();
game.BiosSet = biossets.ToArray();
game.Rom = roms.ToArray();
game.Disk = disks.ToArray();
game.Media = medias.ToArray();
game.Sample = samples.ToArray();
game.Archive = archives.ToArray();
game.DeviceRef = devicerefs.ToArray();
game.SoftwareList = softwarelists.ToArray();
game.Release = [.. releases];
game.BiosSet = [.. biossets];
game.Rom = [.. roms];
game.Disk = [.. disks];
game.Media = [.. medias];
game.Sample = [.. samples];
game.Archive = [.. archives];
game.DeviceRef = [.. devicerefs];
game.SoftwareList = [.. softwarelists];
// Add the game to the list
games.Add(game);
}
return games.ToArray();
return [.. games];
}
/// <summary>
@@ -410,7 +410,7 @@ namespace SabreTools.DatFiles.Formats
if (machine.Comment.Contains(';'))
game.Comment = machine.Comment.Split(';');
else
game.Comment = new[] { machine.Comment };
game.Comment = [machine.Comment];
}
game.Description = machine.Description;
game.Year = machine.Year;
@@ -421,7 +421,7 @@ namespace SabreTools.DatFiles.Formats
if (machine.Category.Contains(';'))
game.Category = machine.Category.Split(';');
else
game.Category = new[] { machine.Category };
game.Category = [machine.Category];
}
game.Trurip = CreateTrurip(machine);

View File

@@ -22,7 +22,7 @@ namespace SabreTools.DatFiles.Formats
var dat = new Serialization.Files.OfflineList().Deserialize(filename);
// Convert the header to the internal format
ConvertHeader(dat);
OfflineList.ConvertHeader(dat);
// Convert the configuration to the internal format
ConvertConfiguration(dat?.Configuration, keep);
@@ -46,7 +46,7 @@ namespace SabreTools.DatFiles.Formats
/// Convert header information
/// </summary>
/// <param name="dat">Deserialized model to convert</param>
private void ConvertHeader(Models.OfflineList.Dat? dat)
private static void ConvertHeader(Models.OfflineList.Dat? dat)
{
// If the datafile is missing, we can't do anything
if (dat == null)
@@ -260,7 +260,7 @@ namespace SabreTools.DatFiles.Formats
/// Convert search information
/// </summary>
/// <param name="search">Deserialized model to convert</param>
private void ConvertSearch(Models.OfflineList.Search? search)
private static void ConvertSearch(Models.OfflineList.Search? search)
{
// If the search or to array is missing, we can't do anything
if (search?.To == null)
@@ -391,7 +391,7 @@ namespace SabreTools.DatFiles.Formats
/// Convert GUI information
/// </summary>
/// <param name="gui">Deserialized model to convert</param>
private void ConvertGUI(Models.OfflineList.GUI? gui)
private static void ConvertGUI(Models.OfflineList.GUI? gui)
{
// If the gui or Images are missing, we can't do anything
if (gui?.Images?.Image == null || !gui.Images.Image.Any())

View File

@@ -15,10 +15,10 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[]
{
return
[
ItemType.Rom
};
];
}
/// <inheritdoc/>
@@ -261,7 +261,7 @@ namespace SabreTools.DatFiles.Formats
var canOpen = new Models.OfflineList.CanOpen
{
Extension = Header.CanOpen.ToArray(),
Extension = [.. Header.CanOpen],
};
return canOpen;
@@ -321,7 +321,7 @@ namespace SabreTools.DatFiles.Formats
// Get the first item for game information
var machine = items[0].Machine;
var game = CreateGame(machine!);
var game = OfflineList.CreateGame(machine!);
// Create holders for all item types
var romCRCs = new List<Models.OfflineList.FileRomCRC>();
@@ -348,19 +348,19 @@ namespace SabreTools.DatFiles.Formats
}
// Assign the values to the game
game.Files = new Models.OfflineList.Files { RomCRC = romCRCs.ToArray() };
game.Files = new Models.OfflineList.Files { RomCRC = [.. romCRCs] };
// Add the game to the list
games.Add(game);
}
return new Models.OfflineList.Games { Game = games.ToArray() };
return new Models.OfflineList.Games { Game = [.. games] };
}
/// <summary>
/// Create a Machine from the current internal information
/// <summary>
private Models.OfflineList.Game CreateGame(Machine machine)
private static Models.OfflineList.Game CreateGame(Machine machine)
{
var game = new Models.OfflineList.Game

View File

@@ -15,10 +15,10 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[]
{
return
[
ItemType.Rom
};
];
}
/// <inheritdoc/>
@@ -137,11 +137,11 @@ namespace SabreTools.DatFiles.Formats
}
}
software.Dump = dumps.ToArray();
software.Dump = [.. dumps];
softwares.Add(software);
}
return softwares.ToArray();
return [.. softwares];
}
/// <summary>

View File

@@ -15,16 +15,16 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[]
{
return
[
ItemType.Rom
};
];
}
/// <inheritdoc/>
protected override List<DatItemField>? GetMissingRequiredFields(DatItem datItem)
{
List<DatItemField> missingFields = new();
List<DatItemField> missingFields = [];
// Check item name
if (string.IsNullOrWhiteSpace(datItem.GetName()))
@@ -173,7 +173,7 @@ namespace SabreTools.DatFiles.Formats
}
}
return new Models.RomCenter.Games { Rom = roms.ToArray() };
return new Models.RomCenter.Games { Rom = [.. roms] };
}
/// <summary>

View File

@@ -115,7 +115,7 @@ namespace SabreTools.DatFiles.Formats
JArray? machineArray = js.Deserialize<JArray>(jtr);
// Loop through each machine object and process
foreach (JObject machineObj in machineArray ?? new JArray())
foreach (JObject machineObj in (machineArray ?? []).Cast<JObject>())
{
ReadMachine(machineObj, statsOnly, filename, indexId);
}
@@ -170,7 +170,7 @@ namespace SabreTools.DatFiles.Formats
return;
// Loop through each datitem object and process
foreach (JObject itemObj in itemsArr)
foreach (JObject itemObj in itemsArr.Cast<JObject>())
{
ReadItem(itemObj, statsOnly, filename, indexId, machine);
}
@@ -396,11 +396,11 @@ namespace SabreTools.DatFiles.Formats
// If we have a different game and we're not at the start of the list, output the end of last item
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name?.ToLowerInvariant())
WriteEndGame(jtw);
SabreJSON.WriteEndGame(jtw);
// If we have a new game, output the beginning of the new item
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name?.ToLowerInvariant())
WriteStartGame(jtw, datItem);
SabreJSON.WriteStartGame(jtw, datItem);
// Check for a "null" item
datItem = ProcessNullifiedItem(datItem);
@@ -415,7 +415,7 @@ namespace SabreTools.DatFiles.Formats
}
// Write the file footer out
WriteFooter(jtw);
SabreJSON.WriteFooter(jtw);
logger.User($"'{outfile}' written!{Environment.NewLine}");
jtw.Close();
@@ -454,7 +454,7 @@ namespace SabreTools.DatFiles.Formats
/// </summary>
/// <param name="jtw">JsonTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
private void WriteStartGame(JsonTextWriter jtw, DatItem datItem)
private static void WriteStartGame(JsonTextWriter jtw, DatItem datItem)
{
// No game should start with a path separator
if (!string.IsNullOrWhiteSpace(datItem.Machine.Name))
@@ -478,7 +478,7 @@ namespace SabreTools.DatFiles.Formats
/// Write out Game end using the supplied JsonTextWriter
/// </summary>
/// <param name="jtw">JsonTextWriter to output to</param>
private void WriteEndGame(JsonTextWriter jtw)
private static void WriteEndGame(JsonTextWriter jtw)
{
// End items
jtw.WriteEndArray();
@@ -517,7 +517,7 @@ namespace SabreTools.DatFiles.Formats
/// Write out DAT footer using the supplied JsonTextWriter
/// </summary>
/// <param name="jtw">JsonTextWriter to output to</param>
private void WriteFooter(JsonTextWriter jtw)
private static void WriteFooter(JsonTextWriter jtw)
{
// End items
jtw.WriteEndArray();

View File

@@ -283,7 +283,7 @@ namespace SabreTools.DatFiles.Formats
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
private void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
private static void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
{
// No game should start with a path separator
datItem.Machine!.Name = datItem.Machine.Name?.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty;
@@ -304,7 +304,7 @@ namespace SabreTools.DatFiles.Formats
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
private void WriteEndGame(XmlTextWriter xtw)
private static void WriteEndGame(XmlTextWriter xtw)
{
// End files
xtw.WriteEndElement();
@@ -338,7 +338,7 @@ namespace SabreTools.DatFiles.Formats
/// Write out DAT footer using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
private void WriteFooter(XmlTextWriter xtw)
private static void WriteFooter(XmlTextWriter xtw)
{
// End files
xtw.WriteEndElement();

View File

@@ -16,18 +16,18 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[]
{
return
[
ItemType.Disk,
ItemType.Media,
ItemType.Rom
};
];
}
/// <inheritdoc/>
protected override List<DatItemField>? GetMissingRequiredFields(DatItem datItem)
{
List<DatItemField> missingFields = new();
List<DatItemField> missingFields = [];
// Check item name
if (string.IsNullOrWhiteSpace(datItem.GetName()))
@@ -149,7 +149,7 @@ namespace SabreTools.DatFiles.Formats
}
}
return rows.ToArray();
return [.. rows];
}
/// <summary>

View File

@@ -101,7 +101,7 @@ namespace SabreTools.DatFiles.Formats
};
// Add all Info objects
foreach (var info in software.Info ?? Array.Empty<Models.SoftwareList.Info>())
foreach (var info in software.Info ?? [])
{
var infoItem = new Info
{
@@ -120,7 +120,7 @@ namespace SabreTools.DatFiles.Formats
}
// Add all SharedFeat objects
foreach (var sharedfeat in software.SharedFeat ?? Array.Empty<Models.SoftwareList.SharedFeat>())
foreach (var sharedfeat in software.SharedFeat ?? [])
{
var sharedfeatItem = new SharedFeature
{

View File

@@ -16,14 +16,14 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override ItemType[] GetSupportedTypes()
{
return new ItemType[]
{
return
[
ItemType.DipSwitch,
ItemType.Disk,
ItemType.Info,
ItemType.Rom,
ItemType.SharedFeature,
};
];
}
/// <inheritdoc/>
@@ -241,15 +241,15 @@ namespace SabreTools.DatFiles.Formats
parts = SantitizeParts(parts);
// Assign the values to the game
sw.Info = infos.ToArray();
sw.SharedFeat = sharedfeats.ToArray();
sw.Part = parts.ToArray();
sw.Info = [.. infos];
sw.SharedFeat = [.. sharedfeats];
sw.Part = [.. parts];
// Add the game to the list
software.Add(sw);
}
return software.ToArray();
return [.. software];
}
/// <summary>
@@ -368,7 +368,7 @@ namespace SabreTools.DatFiles.Formats
features.Add(feature);
}
return features.ToArray();
return [.. features];
}
/// <summary>
@@ -384,7 +384,7 @@ namespace SabreTools.DatFiles.Formats
Endianness = item.DataArea?.Endianness.FromEndianness(),
Rom = CreateRom(item),
};
return new Models.SoftwareList.DataArea[] { dataArea };
return [dataArea];
}
/// <summary>
@@ -404,7 +404,7 @@ namespace SabreTools.DatFiles.Formats
Status = item.ItemStatus.FromItemStatus(yesno: false),
LoadFlag = item.LoadFlag.FromLoadFlag(),
};
return new Models.SoftwareList.Rom[] { rom };
return [rom];
}
/// <summary>
@@ -416,7 +416,7 @@ namespace SabreTools.DatFiles.Formats
{
Disk = CreateDisk(item),
};
return new Models.SoftwareList.DiskArea[] { diskArea };
return [diskArea];
}
/// <summary>
@@ -432,7 +432,7 @@ namespace SabreTools.DatFiles.Formats
Status = item.ItemStatus.FromItemStatus(yesno: false),
Writeable = item.Writable?.ToString(),
};
return new Models.SoftwareList.Disk[] { disk };
return [disk];
}
/// <summary>
@@ -441,7 +441,7 @@ namespace SabreTools.DatFiles.Formats
private static Models.SoftwareList.DipSwitch[]? CreateDipSwitches(DipSwitch item)
{
var dipValues = new List<Models.SoftwareList.DipValue>();
foreach (var setting in item.Values ?? new List<DipValue>())
foreach (var setting in item.Values ?? [])
{
var dipValue = new Models.SoftwareList.DipValue
{
@@ -452,8 +452,8 @@ namespace SabreTools.DatFiles.Formats
dipValues.Add(dipValue);
}
var dipSwitch = new Models.SoftwareList.DipSwitch { DipValue = dipValues.ToArray() };
return new Models.SoftwareList.DipSwitch[] { dipSwitch };
var dipSwitch = new Models.SoftwareList.DipSwitch { DipValue = [.. dipValues] };
return [dipSwitch];
}
/// <summary>
@@ -496,13 +496,13 @@ namespace SabreTools.DatFiles.Formats
tempDiskAreas = SantitizeDiskAreas(tempDiskAreas);
if (tempFeatures.Count > 0)
tempPart.Feature = tempFeatures.ToArray();
tempPart.Feature = [.. tempFeatures];
if (tempDataAreas.Count > 0)
tempPart.DataArea = tempDataAreas.ToArray();
tempPart.DataArea = [.. tempDataAreas];
if (tempDiskAreas.Count > 0)
tempPart.DiskArea = tempDiskAreas.ToArray();
tempPart.DiskArea = [.. tempDiskAreas];
if (tempDipSwitches.Count > 0)
tempPart.DipSwitch = tempDipSwitches.ToArray();
tempPart.DipSwitch = [.. tempDipSwitches];
tempParts.Add(tempPart);
}
@@ -539,7 +539,7 @@ namespace SabreTools.DatFiles.Formats
}
if (tempRoms.Count > 0)
tempDataArea.Rom = tempRoms.ToArray();
tempDataArea.Rom = [.. tempRoms];
tempDataAreas.Add(tempDataArea);
}
@@ -572,7 +572,7 @@ namespace SabreTools.DatFiles.Formats
}
if (tempDisks.Count > 0)
tempDiskArea.Disk = tempDisks.ToArray();
tempDiskArea.Disk = [.. tempDisks];
tempDiskAreas.Add(tempDiskArea);
}

View File

@@ -709,7 +709,7 @@ namespace SabreTools.DatFiles
{
// If the key is missing from the dictionary, add it
if (!items.ContainsKey(key))
items.TryAdd(key, new ConcurrentList<DatItem>());
items.TryAdd(key, []);
}
/// <summary>
@@ -723,7 +723,7 @@ namespace SabreTools.DatFiles
// Get the list, if possible
ConcurrentList<DatItem>? fi = items[key];
if (fi == null)
return new ConcurrentList<DatItem>();
return [];
// Filter the list
return fi.Where(i => i != null)
@@ -795,7 +795,7 @@ namespace SabreTools.DatFiles
}
// Remove the key from the dictionary
items[key] = new ConcurrentList<DatItem>();
items[key] = [];
return true;
}
@@ -996,7 +996,7 @@ namespace SabreTools.DatFiles
mergedBy = DedupeType.None;
// First do the initial sort of all of the roms inplace
List<string> oldkeys = Keys.ToList();
List<string> oldkeys = [.. Keys];
Parallel.For(0, oldkeys.Count, Globals.ParallelOptions, k =>
{
string key = oldkeys[k];
@@ -1036,7 +1036,7 @@ namespace SabreTools.DatFiles
// Set the sorted type
mergedBy = dedupeType;
List<string> keys = Keys.ToList();
List<string> keys = [.. Keys];
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
{
// Get the possibly unsorted list
@@ -1059,7 +1059,7 @@ namespace SabreTools.DatFiles
// If the merge type is the same, we want to sort the dictionary to be consistent
else
{
List<string> keys = Keys.ToList();
List<string> keys = [.. Keys];
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
{
// Get the possibly unsorted list
@@ -1118,7 +1118,7 @@ namespace SabreTools.DatFiles
/// <returns>List of matched DatItem objects</returns>
public ConcurrentList<DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
{
ConcurrentList<DatItem> output = new();
ConcurrentList<DatItem> output = [];
// Check for an empty rom list first
if (TotalCount == 0)
@@ -1136,7 +1136,7 @@ namespace SabreTools.DatFiles
if (roms == null)
return output;
ConcurrentList<DatItem> left = new();
ConcurrentList<DatItem> left = [];
for (int i = 0; i < roms.Count; i++)
{
DatItem other = roms[i];

View File

@@ -17,9 +17,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SabreTools.IO" Version="1.2.0" />
<PackageReference Include="SabreTools.Models" Version="1.2.0" />
<PackageReference Include="SabreTools.Serialization" Version="1.2.0" />
<PackageReference Include="SabreTools.IO" Version="1.3.0" />
<PackageReference Include="SabreTools.Models" Version="1.3.0" />
<PackageReference Include="SabreTools.Serialization" Version="1.3.0" />
</ItemGroup>
</Project>

View File

@@ -51,9 +51,9 @@ namespace SabreTools.DatFiles
public void PopulateSettersFromList(List<string> headers, List<string> fields)
{
// Instantiate the setters, if necessary
DatHeaderMappings ??= new Dictionary<DatHeaderField, string>();
MachineMappings ??= new Dictionary<MachineField, string>();
DatItemMappings ??= new Dictionary<DatItemField, string>();
DatHeaderMappings ??= [];
MachineMappings ??= [];
DatItemMappings ??= [];
// If the list is null or empty, just return
if (fields == null || fields.Count == 0)