diff --git a/SabreTools.Serialization/Internal.ArchiveDotOrg.cs b/SabreTools.Serialization/Internal.ArchiveDotOrg.cs
index 9760a1ec..f8825c63 100644
--- a/SabreTools.Serialization/Internal.ArchiveDotOrg.cs
+++ b/SabreTools.Serialization/Internal.ArchiveDotOrg.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Linq;
namespace SabreTools.Serialization
{
@@ -102,24 +102,23 @@ namespace SabreTools.Serialization
///
/// Convert from to an array of
///
- public static Models.ArchiveDotOrg.File[]? ConvertMachineToArchiveDotOrg(Models.Internal.Machine item)
+ public static Models.ArchiveDotOrg.File?[]? ConvertMachineToArchiveDotOrg(Models.Internal.Machine? item)
{
- if (!item.ContainsKey(Models.Internal.Machine.RomKey) || item[Models.Internal.Machine.RomKey] is not Models.Internal.Rom[] roms)
+ if (item == null)
return null;
- var fileItems = new List();
- foreach (var rom in roms)
- {
- fileItems.Add(ConvertToArchiveDotOrg(rom));
- }
- return fileItems.ToArray();
+ var roms = item.Read(Models.Internal.Machine.RomKey);
+ return roms?.Select(ConvertToArchiveDotOrg)?.ToArray();
}
///
/// Convert from to
///
- public static Models.ArchiveDotOrg.File ConvertToArchiveDotOrg(Models.Internal.Rom item)
+ public static Models.ArchiveDotOrg.File? ConvertToArchiveDotOrg(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var file = new Models.ArchiveDotOrg.File
{
Name = item.ReadString(Models.Internal.Rom.NameKey),
diff --git a/SabreTools.Serialization/Internal.AttractMode.cs b/SabreTools.Serialization/Internal.AttractMode.cs
index bc6527cd..1b2da2f2 100644
--- a/SabreTools.Serialization/Internal.AttractMode.cs
+++ b/SabreTools.Serialization/Internal.AttractMode.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Linq;
namespace SabreTools.Serialization
{
@@ -62,14 +63,17 @@ namespace SabreTools.Serialization
///
/// Convert from to an array of
///
- public static Models.AttractMode.Row[]? ConvertMachineToAttractMode(Models.Internal.Machine item)
+ public static Models.AttractMode.Row?[]? ConvertMachineToAttractMode(Models.Internal.Machine? item)
{
- if (!item.ContainsKey(Models.Internal.Machine.RomKey) || item[Models.Internal.Machine.RomKey] is not Models.Internal.Rom[] roms)
+ if (item == null)
return null;
- var rowItems = new List();
- foreach (var rom in roms)
+ var roms = item.Read(Models.Internal.Machine.RomKey);
+ return roms?.Select(rom =>
{
+ if (rom == null)
+ return null;
+
var rowItem = ConvertToAttractMode(rom);
rowItem.Name = item.ReadString(Models.Internal.Machine.NameKey);
@@ -91,16 +95,18 @@ namespace SabreTools.Serialization
rowItem.PlayedCount = item.ReadString(Models.Internal.Machine.PlayedCountKey);
rowItem.PlayedTime = item.ReadString(Models.Internal.Machine.PlayedTimeKey);
- rowItems.Add(rowItem);
- }
- return rowItems.ToArray();
+ return rowItem;
+ })?.ToArray();
}
///
/// Convert from to
///
- public static Models.AttractMode.Row ConvertToAttractMode(Models.Internal.Rom item)
+ public static Models.AttractMode.Row? ConvertToAttractMode(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var row = new Models.AttractMode.Row
{
Title = item.ReadString(Models.Internal.Rom.NameKey),
diff --git a/SabreTools.Serialization/Internal.ClrMamePro.cs b/SabreTools.Serialization/Internal.ClrMamePro.cs
index 237c1a9b..aab71462 100644
--- a/SabreTools.Serialization/Internal.ClrMamePro.cs
+++ b/SabreTools.Serialization/Internal.ClrMamePro.cs
@@ -350,8 +350,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.GameBase ConvertMachineToClrMamePro(Models.Internal.Machine item, bool game = false)
+ public static Models.ClrMamePro.GameBase? ConvertMachineToClrMamePro(Models.Internal.Machine? item, bool game = false)
{
+ if (item == null)
+ return null;
+
Models.ClrMamePro.GameBase gameBase = game ? new Models.ClrMamePro.Game() : new Models.ClrMamePro.Machine();
gameBase.Name = item.ReadString(Models.Internal.Machine.NameKey);
@@ -363,107 +366,44 @@ namespace SabreTools.Serialization
gameBase.RomOf = item.ReadString(Models.Internal.Machine.RomOfKey);
gameBase.SampleOf = item.ReadString(Models.Internal.Machine.SampleOfKey);
- if (item.ContainsKey(Models.Internal.Machine.ReleaseKey) && item[Models.Internal.Machine.ReleaseKey] is Models.Internal.Release[] releases)
- {
- var releaseItems = new List();
- foreach (var release in releases)
- {
- releaseItems.Add(ConvertToClrMamePro(release));
- }
- gameBase.Release = releaseItems.ToArray();
- }
+ var releases = item.Read(Models.Internal.Machine.ReleaseKey);
+ gameBase.Release = releases?.Select(ConvertToClrMamePro)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.BiosSetKey) && item[Models.Internal.Machine.BiosSetKey] is Models.Internal.BiosSet[] biosSets)
- {
- var biosSetItems = new List();
- foreach (var biosSet in biosSets)
- {
- biosSetItems.Add(ConvertToClrMamePro(biosSet));
- }
- gameBase.BiosSet = biosSetItems.ToArray();
- }
+ var biosSets = item.Read(Models.Internal.Machine.BiosSetKey);
+ gameBase.BiosSet = biosSets?.Select(ConvertToClrMamePro)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.RomKey) && item[Models.Internal.Machine.RomKey] is Models.Internal.Rom[] roms)
- {
- var romItems = new List();
- foreach (var rom in roms)
- {
- romItems.Add(ConvertToClrMamePro(rom));
- }
- gameBase.Rom = romItems.ToArray();
- }
+ var roms = item.Read(Models.Internal.Machine.RomKey);
+ gameBase.Rom = roms?.Select(ConvertToClrMamePro)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.DiskKey) && item[Models.Internal.Machine.DiskKey] is Models.Internal.Disk[] disks)
- {
- var diskItems = new List();
- foreach (var disk in disks)
- {
- diskItems.Add(ConvertToClrMamePro(disk));
- }
- gameBase.Disk = diskItems.ToArray();
- }
+ var disks = item.Read(Models.Internal.Machine.DiskKey);
+ gameBase.Disk = disks?.Select(ConvertToClrMamePro)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.MediaKey) && item[Models.Internal.Machine.MediaKey] is Models.Internal.Media[] medias)
- {
- var mediaItems = new List();
- foreach (var media in medias)
- {
- mediaItems.Add(ConvertToClrMamePro(media));
- }
- gameBase.Media = mediaItems.ToArray();
- }
+ var medias = item.Read(Models.Internal.Machine.MediaKey);
+ gameBase.Media = medias?.Select(ConvertToClrMamePro)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.SampleKey) && item[Models.Internal.Machine.SampleKey] is Models.Internal.Sample[] samples)
- {
- var sampleItems = new List();
- foreach (var sample in samples)
- {
- sampleItems.Add(ConvertToClrMamePro(sample));
- }
- gameBase.Sample = sampleItems.ToArray();
- }
+ var samples = item.Read(Models.Internal.Machine.SampleKey);
+ gameBase.Sample = samples?.Select(ConvertToClrMamePro)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.ArchiveKey) && item[Models.Internal.Machine.ArchiveKey] is Models.Internal.Archive[] archives)
- {
- var archiveItems = new List();
- foreach (var archive in archives)
- {
- archiveItems.Add(ConvertToClrMamePro(archive));
- }
- gameBase.Archive = archiveItems.ToArray();
- }
+ var archives = item.Read(Models.Internal.Machine.ArchiveKey);
+ gameBase.Archive = archives?.Select(ConvertToClrMamePro)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.ChipKey) && item[Models.Internal.Machine.ChipKey] is Models.Internal.Chip[] chips)
- {
- var chipItems = new List();
- foreach (var chip in chips)
- {
- chipItems.Add(ConvertToClrMamePro(chip));
- }
- gameBase.Chip = chipItems.ToArray();
- }
+ var chips = item.Read(Models.Internal.Machine.ChipKey);
+ gameBase.Chip = chips?.Select(ConvertToClrMamePro)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.VideoKey) && item[Models.Internal.Machine.VideoKey] is Models.Internal.Video video)
- gameBase.Video = ConvertToClrMamePro(video);
+ var video = item.Read(Models.Internal.Machine.VideoKey);
+ gameBase.Video = ConvertToClrMamePro(video);
- if (item.ContainsKey(Models.Internal.Machine.SoundKey) && item[Models.Internal.Machine.SoundKey] is Models.Internal.Sound sound)
- gameBase.Sound = ConvertToClrMamePro(sound);
+ var sound = item.Read(Models.Internal.Machine.SoundKey);
+ gameBase.Sound = ConvertToClrMamePro(sound);
- if (item.ContainsKey(Models.Internal.Machine.InputKey) && item[Models.Internal.Machine.InputKey] is Models.Internal.Input input)
- gameBase.Input = ConvertToClrMamePro(input);
+ var input = item.Read(Models.Internal.Machine.InputKey);
+ gameBase.Input = ConvertToClrMamePro(input);
- if (item.ContainsKey(Models.Internal.Machine.DipSwitchKey) && item[Models.Internal.Machine.DipSwitchKey] is Models.Internal.DipSwitch[] dipSwitches)
- {
- var dipSwitchItems = new List();
- foreach (var dipSwitch in dipSwitches)
- {
- dipSwitchItems.Add(ConvertToClrMamePro(dipSwitch));
- }
- gameBase.DipSwitch = dipSwitchItems.ToArray();
- }
+ var dipSwitches = item.Read(Models.Internal.Machine.DipSwitchKey);
+ gameBase.DipSwitch = dipSwitches?.Select(ConvertToClrMamePro)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.DriverKey) && item[Models.Internal.Machine.DriverKey] is Models.Internal.Driver driver)
- gameBase.Driver = ConvertToClrMamePro(driver);
+ var driver = item.Read(Models.Internal.Machine.DriverKey);
+ gameBase.Driver = ConvertToClrMamePro(driver);
return gameBase;
}
@@ -471,8 +411,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.Archive ConvertToClrMamePro(Models.Internal.Archive item)
+ public static Models.ClrMamePro.Archive? ConvertToClrMamePro(Models.Internal.Archive? item)
{
+ if (item == null)
+ return null;
+
var archive = new Models.ClrMamePro.Archive
{
Name = item.ReadString(Models.Internal.Archive.NameKey),
@@ -483,8 +426,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.BiosSet ConvertToClrMamePro(Models.Internal.BiosSet item)
+ public static Models.ClrMamePro.BiosSet? ConvertToClrMamePro(Models.Internal.BiosSet? item)
{
+ if (item == null)
+ return null;
+
var biosset = new Models.ClrMamePro.BiosSet
{
Name = item.ReadString(Models.Internal.BiosSet.NameKey),
@@ -497,8 +443,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.Chip ConvertToClrMamePro(Models.Internal.Chip item)
+ public static Models.ClrMamePro.Chip? ConvertToClrMamePro(Models.Internal.Chip? item)
{
+ if (item == null)
+ return null;
+
var chip = new Models.ClrMamePro.Chip
{
Type = item.ReadString(Models.Internal.Chip.ChipTypeKey),
@@ -512,8 +461,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.DipSwitch ConvertToClrMamePro(Models.Internal.DipSwitch item)
+ public static Models.ClrMamePro.DipSwitch? ConvertToClrMamePro(Models.Internal.DipSwitch? item)
{
+ if (item == null)
+ return null;
+
var dipswitch = new Models.ClrMamePro.DipSwitch
{
Name = item.ReadString(Models.Internal.DipSwitch.NameKey),
@@ -526,8 +478,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.Disk ConvertToClrMamePro(Models.Internal.Disk item)
+ public static Models.ClrMamePro.Disk? ConvertToClrMamePro(Models.Internal.Disk? item)
{
+ if (item == null)
+ return null;
+
var disk = new Models.ClrMamePro.Disk
{
Name = item.ReadString(Models.Internal.Disk.NameKey),
@@ -543,8 +498,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.Driver ConvertToClrMamePro(Models.Internal.Driver item)
+ public static Models.ClrMamePro.Driver? ConvertToClrMamePro(Models.Internal.Driver? item)
{
+ if (item == null)
+ return null;
+
var driver = new Models.ClrMamePro.Driver
{
Status = item.ReadString(Models.Internal.Driver.StatusKey),
@@ -559,8 +517,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.Input ConvertToClrMamePro(Models.Internal.Input item)
+ public static Models.ClrMamePro.Input? ConvertToClrMamePro(Models.Internal.Input? item)
{
+ if (item == null)
+ return null;
+
var input = new Models.ClrMamePro.Input
{
Players = item.ReadString(Models.Internal.Input.PlayersKey),
@@ -576,8 +537,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.Media ConvertToClrMamePro(Models.Internal.Media item)
+ public static Models.ClrMamePro.Media? ConvertToClrMamePro(Models.Internal.Media? item)
{
+ if (item == null)
+ return null;
+
var media = new Models.ClrMamePro.Media
{
Name = item.ReadString(Models.Internal.Media.NameKey),
@@ -592,8 +556,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.Release ConvertToClrMamePro(Models.Internal.Release item)
+ public static Models.ClrMamePro.Release? ConvertToClrMamePro(Models.Internal.Release? item)
{
+ if (item == null)
+ return null;
+
var release = new Models.ClrMamePro.Release
{
Name = item.ReadString(Models.Internal.Release.NameKey),
@@ -608,8 +575,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.Rom ConvertToClrMamePro(Models.Internal.Rom item)
+ public static Models.ClrMamePro.Rom? ConvertToClrMamePro(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var rom = new Models.ClrMamePro.Rom
{
Name = item.ReadString(Models.Internal.Rom.NameKey),
@@ -640,8 +610,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.Sample ConvertToClrMamePro(Models.Internal.Sample item)
+ public static Models.ClrMamePro.Sample? ConvertToClrMamePro(Models.Internal.Sample? item)
{
+ if (item == null)
+ return null;
+
var sample = new Models.ClrMamePro.Sample
{
Name = item.ReadString(Models.Internal.Sample.NameKey),
@@ -652,8 +625,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.Sound ConvertToClrMamePro(Models.Internal.Sound item)
+ public static Models.ClrMamePro.Sound? ConvertToClrMamePro(Models.Internal.Sound? item)
{
+ if (item == null)
+ return null;
+
var sound = new Models.ClrMamePro.Sound
{
Channels = item.ReadString(Models.Internal.Sound.ChannelsKey),
@@ -664,8 +640,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.ClrMamePro.Video ConvertToClrMamePro(Models.Internal.Video item)
+ public static Models.ClrMamePro.Video? ConvertToClrMamePro(Models.Internal.Video? item)
{
+ if (item == null)
+ return null;
+
var video = new Models.ClrMamePro.Video
{
Screen = item.ReadString(Models.Internal.Video.ScreenKey),
diff --git a/SabreTools.Serialization/Internal.DosCenter.cs b/SabreTools.Serialization/Internal.DosCenter.cs
index a67b2a8a..d0fd6dbd 100644
--- a/SabreTools.Serialization/Internal.DosCenter.cs
+++ b/SabreTools.Serialization/Internal.DosCenter.cs
@@ -55,22 +55,18 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.DosCenter.Game ConvertMachineToDosCenter(Models.Internal.Machine item)
+ public static Models.DosCenter.Game? ConvertMachineToDosCenter(Models.Internal.Machine? item)
{
+ if (item == null)
+ return null;
+
var game = new Models.DosCenter.Game
{
Name = item.ReadString(Models.Internal.Machine.NameKey),
};
- if (item.ContainsKey(Models.Internal.Machine.RomKey) && item[Models.Internal.Machine.RomKey] is Models.Internal.Rom[] roms)
- {
- var fileItems = new List();
- foreach (var rom in roms)
- {
- fileItems.Add(ConvertToDosCenter(rom));
- }
- game.File = fileItems.ToArray();
- }
+ var roms = item.Read(Models.Internal.Machine.RomKey);
+ game.File = roms?.Select(ConvertToDosCenter)?.ToArray();
return game;
}
@@ -78,8 +74,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.DosCenter.File ConvertToDosCenter(Models.Internal.Rom item)
+ public static Models.DosCenter.File? ConvertToDosCenter(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var file = new Models.DosCenter.File
{
Name = item.ReadString(Models.Internal.Rom.NameKey),
diff --git a/SabreTools.Serialization/Internal.EverdriveSMDB.cs b/SabreTools.Serialization/Internal.EverdriveSMDB.cs
index ec03d2ad..aeeda92e 100644
--- a/SabreTools.Serialization/Internal.EverdriveSMDB.cs
+++ b/SabreTools.Serialization/Internal.EverdriveSMDB.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Linq;
namespace SabreTools.Serialization
{
@@ -47,22 +48,21 @@ namespace SabreTools.Serialization
///
public static Models.EverdriveSMDB.Row[]? ConvertMachineToEverdriveSMDB(Models.Internal.Machine item)
{
- if (!item.ContainsKey(Models.Internal.Machine.RomKey) || item[Models.Internal.Machine.RomKey] is not Models.Internal.Rom[] roms)
+ if (item == null)
return null;
- var fileItems = new List();
- foreach (var rom in roms)
- {
- fileItems.Add(ConvertToEverdriveSMDB(rom));
- }
- return fileItems.ToArray();
+ var roms = item.Read(Models.Internal.Machine.RomKey);
+ return roms?.Select(ConvertToEverdriveSMDB)?.ToArray();
}
///
/// Convert from to
///
- public static Models.EverdriveSMDB.Row ConvertToEverdriveSMDB(Models.Internal.Rom item)
+ public static Models.EverdriveSMDB.Row? ConvertToEverdriveSMDB(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var row = new Models.EverdriveSMDB.Row
{
SHA256 = item.ReadString(Models.Internal.Rom.SHA256Key),
diff --git a/SabreTools.Serialization/Internal.Hashfile.cs b/SabreTools.Serialization/Internal.Hashfile.cs
index 355335e5..7053eaf0 100644
--- a/SabreTools.Serialization/Internal.Hashfile.cs
+++ b/SabreTools.Serialization/Internal.Hashfile.cs
@@ -189,87 +189,32 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Hashfile.Hashfile ConvertMachineToHashfile(Models.Internal.Machine item, Hash hash)
+ public static Models.Hashfile.Hashfile? ConvertMachineToHashfile(Models.Internal.Machine? item, Hash hash)
{
- var hashfile = new Models.Hashfile.Hashfile();
+ if (item == null)
+ return null;
- if (item.ContainsKey(Models.Internal.Machine.RomKey) && item[Models.Internal.Machine.RomKey] is Models.Internal.Rom[] roms)
+ var roms = item.Read(Models.Internal.Machine.RomKey);
+ return new Models.Hashfile.Hashfile
{
- switch (hash)
- {
- case Hash.CRC:
- var sfvItems = new List();
- foreach (var rom in roms)
- {
- sfvItems.Add(ConvertToSFV(rom));
- }
- hashfile.SFV = sfvItems.ToArray();
- break;
-
- case Hash.MD5:
- var md5Items = new List();
- foreach (var rom in roms)
- {
- md5Items.Add(ConvertToMD5(rom));
- }
- hashfile.MD5 = md5Items.ToArray();
- break;
-
- case Hash.SHA1:
- var sha1Items = new List();
- foreach (var rom in roms)
- {
- sha1Items.Add(ConvertToSHA1(rom));
- }
- hashfile.SHA1 = sha1Items.ToArray();
- break;
-
- case Hash.SHA256:
- var sha256Items = new List();
- foreach (var rom in roms)
- {
- sha256Items.Add(ConvertToSHA256(rom));
- }
- hashfile.SHA256 = sha256Items.ToArray();
- break;
-
- case Hash.SHA384:
- var sha384Items = new List();
- foreach (var rom in roms)
- {
- sha384Items.Add(ConvertToSHA384(rom));
- }
- hashfile.SHA384 = sha384Items.ToArray();
- break;
-
- case Hash.SHA512:
- var sha512Items = new List();
- foreach (var rom in roms)
- {
- sha512Items.Add(ConvertToSHA512(rom));
- }
- hashfile.SHA512 = sha512Items.ToArray();
- break;
-
- case Hash.SpamSum:
- var spamSumItems = new List();
- foreach (var rom in roms)
- {
- spamSumItems.Add(ConvertToSpamSum(rom));
- }
- hashfile.SpamSum = spamSumItems.ToArray();
- break;
- }
- }
-
- return hashfile;
+ SFV = hash == Hash.CRC ? roms?.Select(ConvertToSFV)?.ToArray() : null,
+ MD5 = hash == Hash.MD5 ? roms?.Select(ConvertToMD5)?.ToArray() : null,
+ SHA1 = hash == Hash.SHA1 ? roms?.Select(ConvertToSHA1)?.ToArray() : null,
+ SHA256 = hash == Hash.SHA256 ? roms?.Select(ConvertToSHA256)?.ToArray() : null,
+ SHA384 = hash == Hash.SHA384 ? roms?.Select(ConvertToSHA384)?.ToArray() : null,
+ SHA512 = hash == Hash.SHA512 ? roms?.Select(ConvertToSHA512)?.ToArray() : null,
+ SpamSum = hash == Hash.SpamSum ? roms?.Select(ConvertToSpamSum)?.ToArray() : null,
+ };
}
///
/// Convert from to
///
- public static Models.Hashfile.MD5 ConvertToMD5(Models.Internal.Rom item)
+ public static Models.Hashfile.MD5? ConvertToMD5(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var md5 = new Models.Hashfile.MD5
{
Hash = item.ReadString(Models.Internal.Rom.MD5Key),
@@ -281,8 +226,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Hashfile.SFV ConvertToSFV(Models.Internal.Rom item)
+ public static Models.Hashfile.SFV? ConvertToSFV(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var sfv = new Models.Hashfile.SFV
{
File = item.ReadString(Models.Internal.Rom.NameKey),
@@ -294,8 +242,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Hashfile.SHA1 ConvertToSHA1(Models.Internal.Rom item)
+ public static Models.Hashfile.SHA1? ConvertToSHA1(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var sha1 = new Models.Hashfile.SHA1
{
Hash = item.ReadString(Models.Internal.Rom.SHA1Key),
@@ -307,8 +258,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Hashfile.SHA256 ConvertToSHA256(Models.Internal.Rom item)
+ public static Models.Hashfile.SHA256? ConvertToSHA256(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var sha256 = new Models.Hashfile.SHA256
{
Hash = item.ReadString(Models.Internal.Rom.SHA256Key),
@@ -320,8 +274,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Hashfile.SHA384 ConvertToSHA384(Models.Internal.Rom item)
+ public static Models.Hashfile.SHA384? ConvertToSHA384(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var sha384 = new Models.Hashfile.SHA384
{
Hash = item.ReadString(Models.Internal.Rom.SHA384Key),
@@ -333,8 +290,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Hashfile.SHA512 ConvertToSHA512(Models.Internal.Rom item)
+ public static Models.Hashfile.SHA512? ConvertToSHA512(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var sha512 = new Models.Hashfile.SHA512
{
Hash = item.ReadString(Models.Internal.Rom.SHA512Key),
@@ -346,8 +306,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Hashfile.SpamSum ConvertToSpamSum(Models.Internal.Rom item)
+ public static Models.Hashfile.SpamSum? ConvertToSpamSum(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var spamsum = new Models.Hashfile.SpamSum
{
Hash = item.ReadString(Models.Internal.Rom.SpamSumKey),
diff --git a/SabreTools.Serialization/Internal.Listrom.cs b/SabreTools.Serialization/Internal.Listrom.cs
index 722051de..86c5ddd9 100644
--- a/SabreTools.Serialization/Internal.Listrom.cs
+++ b/SabreTools.Serialization/Internal.Listrom.cs
@@ -34,8 +34,8 @@ namespace SabreTools.Serialization
datItems.Add(ConvertFromListrom(file));
}
- machine[Models.Internal.Machine.DiskKey] = datItems.Where(i => i.ReadString(Models.Internal.DatItem.TypeKey) == "disk").ToArray();
- machine[Models.Internal.Machine.RomKey] = datItems.Where(i => i.ReadString(Models.Internal.DatItem.TypeKey) == "rom").ToArray();
+ machine[Models.Internal.Machine.DiskKey] = datItems.Where(i => i.ReadString(Models.Internal.DatItem.TypeKey) == "disk")?.ToArray();
+ machine[Models.Internal.Machine.RomKey] = datItems.Where(i => i.ReadString(Models.Internal.DatItem.TypeKey) == "rom")?.ToArray();
}
return machine;
@@ -88,8 +88,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listrom.Set ConvertMachineToListrom(Models.Internal.Machine item)
+ public static Models.Listrom.Set? ConvertMachineToListrom(Models.Internal.Machine? item)
{
+ if (item == null)
+ return null;
+
var set = new Models.Listrom.Set();
if (item.ReadString(Models.Internal.Machine.IsDeviceKey) == "yes")
set.Device = item.ReadString(Models.Internal.Machine.NameKey);
@@ -98,33 +101,26 @@ namespace SabreTools.Serialization
var rowItems = new List();
- if (item.ContainsKey(Models.Internal.Machine.RomKey) && item[Models.Internal.Machine.RomKey] is Models.Internal.Rom[] roms)
- {
- foreach (var rom in roms)
- {
- rowItems.Add(ConvertToListrom(rom));
- }
- }
+ var roms = item.Read(Models.Internal.Machine.RomKey);
+ if (roms != null)
+ rowItems.AddRange(roms.Select(ConvertToListrom));
- if (item.ContainsKey(Models.Internal.Machine.DiskKey) && item[Models.Internal.Machine.DiskKey] is Models.Internal.Disk[] disks)
- {
- foreach (var disk in disks)
- {
- rowItems.Add(ConvertToListrom(disk));
- }
- }
-
- if (rowItems.Any())
- set.Row = rowItems.ToArray();
+ var disks = item.Read(Models.Internal.Machine.DiskKey);
+ if (disks != null)
+ rowItems.AddRange(disks.Select(ConvertToListrom));
+ set.Row = rowItems.ToArray();
return set;
}
///
/// Convert from to
///
- public static Models.Listrom.Row ConvertToListrom(Models.Internal.Disk item)
+ public static Models.Listrom.Row? ConvertToListrom(Models.Internal.Disk? item)
{
+ if (item == null)
+ return null;
+
var row = new Models.Listrom.Row
{
Name = item.ReadString(Models.Internal.Disk.NameKey),
@@ -143,8 +139,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listrom.Row ConvertToListrom(Models.Internal.Rom item)
+ public static Models.Listrom.Row? ConvertToListrom(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var row = new Models.Listrom.Row
{
Name = item.ReadString(Models.Internal.Rom.NameKey),
diff --git a/SabreTools.Serialization/Internal.Listxml.cs b/SabreTools.Serialization/Internal.Listxml.cs
index 044a07d3..9ed0af85 100644
--- a/SabreTools.Serialization/Internal.Listxml.cs
+++ b/SabreTools.Serialization/Internal.Listxml.cs
@@ -787,8 +787,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.GameBase ConvertMachineToListxml(Models.Internal.Machine item)
+ public static Models.Listxml.GameBase? ConvertMachineToListxml(Models.Internal.Machine? item)
{
+ if (item == null)
+ return null;
+
var machine = new Models.Listxml.Machine
{
Name = item.ReadString(Models.Internal.Machine.NameKey),
@@ -806,184 +809,65 @@ namespace SabreTools.Serialization
History = item.ReadString(Models.Internal.Machine.HistoryKey),
};
- if (item.ContainsKey(Models.Internal.Machine.BiosSetKey) && item[Models.Internal.Machine.BiosSetKey] is Models.Internal.BiosSet[] biosSets)
- {
- var biosSetItems = new List();
- foreach (var biosSet in biosSets)
- {
- biosSetItems.Add(ConvertToListxml(biosSet));
- }
- machine.BiosSet = biosSetItems.ToArray();
- }
+ var biosSets = item.Read(Models.Internal.Machine.BiosSetKey);
+ machine.BiosSet = biosSets?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.RomKey) && item[Models.Internal.Machine.RomKey] is Models.Internal.Rom[] roms)
- {
- var romItems = new List();
- foreach (var rom in roms)
- {
- romItems.Add(ConvertToListxml(rom));
- }
- machine.Rom = romItems.ToArray();
- }
+ var roms = item.Read(Models.Internal.Machine.RomKey);
+ machine.Rom = roms?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.DiskKey) && item[Models.Internal.Machine.DiskKey] is Models.Internal.Disk[] disks)
- {
- var diskItems = new List();
- foreach (var disk in disks)
- {
- diskItems.Add(ConvertToListxml(disk));
- }
- machine.Disk = diskItems.ToArray();
- }
+ var disks = item.Read(Models.Internal.Machine.DiskKey);
+ machine.Disk = disks?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.DeviceRefKey) && item[Models.Internal.Machine.DeviceRefKey] is Models.Internal.DeviceRef[] deviceRefs)
- {
- var deviceRefItems = new List();
- foreach (var deviceRef in deviceRefs)
- {
- deviceRefItems.Add(ConvertToListxml(deviceRef));
- }
- machine.DeviceRef = deviceRefItems.ToArray();
- }
+ var deviceRefs = item.Read(Models.Internal.Machine.DeviceRefKey);
+ machine.DeviceRef = deviceRefs?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.SampleKey) && item[Models.Internal.Machine.SampleKey] is Models.Internal.Sample[] samples)
- {
- var sampleItems = new List();
- foreach (var sample in samples)
- {
- sampleItems.Add(ConvertToListxml(sample));
- }
- machine.Sample = sampleItems.ToArray();
- }
+ var samples = item.Read(Models.Internal.Machine.SampleKey);
+ machine.Sample = samples?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.ChipKey) && item[Models.Internal.Machine.ChipKey] is Models.Internal.Chip[] chips)
- {
- var chipItems = new List();
- foreach (var chip in chips)
- {
- chipItems.Add(ConvertToListxml(chip));
- }
- machine.Chip = chipItems.ToArray();
- }
+ var chips = item.Read(Models.Internal.Machine.ChipKey);
+ machine.Chip = chips?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.DisplayKey) && item[Models.Internal.Machine.DisplayKey] is Models.Internal.Display[] displays)
- {
- var displayItems = new List();
- foreach (var display in displays)
- {
- displayItems.Add(ConvertToListxml(display));
- }
- machine.Display = displayItems.ToArray();
- }
+ var displays = item.Read(Models.Internal.Machine.DisplayKey);
+ machine.Display = displays?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.VideoKey) && item[Models.Internal.Machine.VideoKey] is Models.Internal.Video[] videos)
- {
- var videoItems = new List();
- foreach (var video in videos)
- {
- videoItems.Add(ConvertToListxml(video));
- }
- machine.Video = videoItems.ToArray();
- }
+ var videos = item.Read(Models.Internal.Machine.VideoKey);
+ machine.Video = videos?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.SoundKey) && item[Models.Internal.Machine.SoundKey] is Models.Internal.Sound sound)
- machine.Sound = ConvertToListxml(sound);
+ var sound = item.Read(Models.Internal.Machine.SoundKey);
+ machine.Sound = ConvertToListxml(sound);
- if (item.ContainsKey(Models.Internal.Machine.InputKey) && item[Models.Internal.Machine.InputKey] is Models.Internal.Input input)
- machine.Input = ConvertToListxml(input);
+ var input = item.Read(Models.Internal.Machine.InputKey);
+ machine.Input = ConvertToListxml(input);
- if (item.ContainsKey(Models.Internal.Machine.DipSwitchKey) && item[Models.Internal.Machine.DipSwitchKey] is Models.Internal.DipSwitch[] dipSwitches)
- {
- var dipSwitchItems = new List();
- foreach (var dipSwitch in dipSwitches)
- {
- dipSwitchItems.Add(ConvertToListxml(dipSwitch));
- }
- machine.DipSwitch = dipSwitchItems.ToArray();
- }
+ var dipSwitches = item.Read(Models.Internal.Machine.DipSwitchKey);
+ machine.DipSwitch = dipSwitches?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.ConfigurationKey) && item[Models.Internal.Machine.ConfigurationKey] is Models.Internal.Configuration[] configurations)
- {
- var configurationItems = new List();
- foreach (var configuration in configurations)
- {
- configurationItems.Add(ConvertToListxml(configuration));
- }
- machine.Configuration = configurationItems.ToArray();
- }
+ var configurations = item.Read(Models.Internal.Machine.ConfigurationKey);
+ machine.Configuration = configurations?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.PortKey) && item[Models.Internal.Machine.PortKey] is Models.Internal.Port[] ports)
- {
- var portItems = new List();
- foreach (var port in ports)
- {
- portItems.Add(ConvertToListxml(port));
- }
- machine.Port = portItems.ToArray();
- }
+ var ports = item.Read(Models.Internal.Machine.PortKey);
+ machine.Port = ports?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.AdjusterKey) && item[Models.Internal.Machine.AdjusterKey] is Models.Internal.Adjuster[] adjusters)
- {
- var adjusterItems = new List();
- foreach (var adjuster in adjusters)
- {
- adjusterItems.Add(ConvertToListxml(adjuster));
- }
- machine.Adjuster = adjusterItems.ToArray();
- }
+ var adjusters = item.Read(Models.Internal.Machine.AdjusterKey);
+ machine.Adjuster = adjusters?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.DriverKey) && item[Models.Internal.Machine.DriverKey] is Models.Internal.Driver driver)
- machine.Driver = ConvertToListxml(driver);
+ var driver = item.Read(Models.Internal.Machine.DriverKey);
+ machine.Driver = ConvertToListxml(driver);
- if (item.ContainsKey(Models.Internal.Machine.FeatureKey) && item[Models.Internal.Machine.FeatureKey] is Models.Internal.Feature[] features)
- {
- var featureItems = new List();
- foreach (var feature in features)
- {
- featureItems.Add(ConvertToListxml(feature));
- }
- machine.Feature = featureItems.ToArray();
- }
+ var features = item.Read(Models.Internal.Machine.FeatureKey);
+ machine.Feature = features?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.DeviceKey) && item[Models.Internal.Machine.DeviceKey] is Models.Internal.Device[] devices)
- {
- var deviceItems = new List();
- foreach (var device in devices)
- {
- deviceItems.Add(ConvertToListxml(device));
- }
- machine.Device = deviceItems.ToArray();
- }
+ var devices = item.Read(Models.Internal.Machine.DeviceKey);
+ machine.Device = devices?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.SlotKey) && item[Models.Internal.Machine.SlotKey] is Models.Internal.Slot[] slots)
- {
- var slotItems = new List();
- foreach (var slot in slots)
- {
- slotItems.Add(ConvertToListxml(slot));
- }
- machine.Slot = slotItems.ToArray();
- }
+ var slots = item.Read(Models.Internal.Machine.SlotKey);
+ machine.Slot = slots?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.SoftwareListKey) && item[Models.Internal.Machine.SoftwareListKey] is Models.Internal.SoftwareList[] softwareLists)
- {
- var softwareListItems = new List();
- foreach (var softwareList in softwareLists)
- {
- softwareListItems.Add(ConvertToListxml(softwareList));
- }
- machine.SoftwareList = softwareListItems.ToArray();
- }
+ var softwareLists = item.Read(Models.Internal.Machine.SoftwareListKey);
+ machine.SoftwareList = softwareLists?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.RamOptionKey) && item[Models.Internal.Machine.RamOptionKey] is Models.Internal.RamOption[] ramOptions)
- {
- var ramOptionItems = new List();
- foreach (var ramOption in ramOptions)
- {
- ramOptionItems.Add(ConvertToListxml(ramOption));
- }
- machine.RamOption = ramOptionItems.ToArray();
- }
+ var ramOptions = item.Read(Models.Internal.Machine.RamOptionKey);
+ machine.RamOption = ramOptions?.Select(ConvertToListxml)?.ToArray();
return machine;
}
@@ -991,16 +875,19 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Adjuster ConvertToListxml(Models.Internal.Adjuster item)
+ public static Models.Listxml.Adjuster? ConvertToListxml(Models.Internal.Adjuster? item)
{
+ if (item == null)
+ return null;
+
var adjuster = new Models.Listxml.Adjuster
{
Name = item.ReadString(Models.Internal.Adjuster.NameKey),
Default = item.ReadString(Models.Internal.Adjuster.DefaultKey),
};
- if (item.ContainsKey(Models.Internal.Adjuster.ConditionKey) && item[Models.Internal.Adjuster.ConditionKey] is Models.Internal.Condition condition)
- adjuster.Condition = ConvertToListxml(condition);
+ var condition = item.Read(Models.Internal.Adjuster.ConditionKey);
+ adjuster.Condition = ConvertToListxml(condition);
return adjuster;
}
@@ -1008,8 +895,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Analog ConvertToListxml(Models.Internal.Analog item)
+ public static Models.Listxml.Analog? ConvertToListxml(Models.Internal.Analog? item)
{
+ if (item == null)
+ return null;
+
var analog = new Models.Listxml.Analog
{
Mask = item.ReadString(Models.Internal.Analog.MaskKey),
@@ -1020,8 +910,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.BiosSet ConvertToListxml(Models.Internal.BiosSet item)
+ public static Models.Listxml.BiosSet? ConvertToListxml(Models.Internal.BiosSet? item)
{
+ if (item == null)
+ return null;
+
var biosset = new Models.Listxml.BiosSet
{
Name = item.ReadString(Models.Internal.BiosSet.NameKey),
@@ -1034,8 +927,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Chip ConvertToListxml(Models.Internal.Chip item)
+ public static Models.Listxml.Chip? ConvertToListxml(Models.Internal.Chip? item)
{
+ if (item == null)
+ return null;
+
var chip = new Models.Listxml.Chip
{
Name = item.ReadString(Models.Internal.Chip.NameKey),
@@ -1050,8 +946,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Condition ConvertToListxml(Models.Internal.Condition item)
+ public static Models.Listxml.Condition? ConvertToListxml(Models.Internal.Condition? item)
{
+ if (item == null)
+ return null;
+
var condition = new Models.Listxml.Condition
{
Tag = item.ReadString(Models.Internal.Condition.TagKey),
@@ -1065,8 +964,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Configuration ConvertToListxml(Models.Internal.Configuration item)
+ public static Models.Listxml.Configuration? ConvertToListxml(Models.Internal.Configuration? item)
{
+ if (item == null)
+ return null;
+
var configuration = new Models.Listxml.Configuration
{
Name = item.ReadString(Models.Internal.Configuration.NameKey),
@@ -1074,28 +976,14 @@ namespace SabreTools.Serialization
Mask = item.ReadString(Models.Internal.Configuration.MaskKey),
};
- if (item.ContainsKey(Models.Internal.Configuration.ConditionKey) && item[Models.Internal.Configuration.ConditionKey] is Models.Internal.Condition condition)
- configuration.Condition = ConvertToListxml(condition);
+ var condition = item.Read(Models.Internal.Configuration.ConditionKey);
+ configuration.Condition = ConvertToListxml(condition);
- if (item.ContainsKey(Models.Internal.Configuration.ConfLocationKey) && item[Models.Internal.Configuration.ConfLocationKey] is Models.Internal.ConfLocation[] confLocations)
- {
- var confLocationItems = new List();
- foreach (var confLocation in confLocations)
- {
- confLocationItems.Add(ConvertToListxml(confLocation));
- }
- configuration.ConfLocation = confLocationItems.ToArray();
- }
+ var confLocations = item.Read(Models.Internal.Configuration.ConfLocationKey);
+ configuration.ConfLocation = confLocations?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.Configuration.ConfSettingKey) && item[Models.Internal.Configuration.ConfSettingKey] is Models.Internal.ConfSetting[] confSettings)
- {
- var confSettingItems = new List();
- foreach (var confSetting in confSettings)
- {
- confSettingItems.Add(ConvertToListxml(confSetting));
- }
- configuration.ConfSetting = confSettingItems.ToArray();
- }
+ var confSettings = item.Read(Models.Internal.Configuration.ConfSettingKey);
+ configuration.ConfSetting = confSettings?.Select(ConvertToListxml)?.ToArray();
return configuration;
}
@@ -1103,8 +991,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.ConfLocation ConvertToListxml(Models.Internal.ConfLocation item)
+ public static Models.Listxml.ConfLocation? ConvertToListxml(Models.Internal.ConfLocation? item)
{
+ if (item == null)
+ return null;
+
var confLocation = new Models.Listxml.ConfLocation
{
Name = item.ReadString(Models.Internal.ConfLocation.NameKey),
@@ -1117,8 +1008,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.ConfSetting ConvertToListxml(Models.Internal.ConfSetting item)
+ public static Models.Listxml.ConfSetting? ConvertToListxml(Models.Internal.ConfSetting? item)
{
+ if (item == null)
+ return null;
+
var confSetting = new Models.Listxml.ConfSetting
{
Name = item.ReadString(Models.Internal.ConfSetting.NameKey),
@@ -1126,8 +1020,8 @@ namespace SabreTools.Serialization
Default = item.ReadString(Models.Internal.ConfSetting.DefaultKey),
};
- if (item.ContainsKey(Models.Internal.ConfSetting.ConditionKey) && item[Models.Internal.ConfSetting.ConditionKey] is Models.Internal.Condition condition)
- confSetting.Condition = ConvertToListxml(condition);
+ var condition = item.Read(Models.Internal.ConfSetting.ConditionKey);
+ confSetting.Condition = ConvertToListxml(condition);
return confSetting;
}
@@ -1135,8 +1029,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Control ConvertToListxml(Models.Internal.Control item)
+ public static Models.Listxml.Control? ConvertToListxml(Models.Internal.Control? item)
{
+ if (item == null)
+ return null;
+
var control = new Models.Listxml.Control
{
Type = item.ReadString(Models.Internal.Control.TypeKey),
@@ -1160,6 +1057,9 @@ namespace SabreTools.Serialization
///
public static Models.Listxml.Device ConvertToListxml(Models.Internal.Device item)
{
+ if (item == null)
+ return null;
+
var device = new Models.Listxml.Device
{
Type = item.ReadString(Models.Internal.Device.TypeKey),
@@ -1169,18 +1069,11 @@ namespace SabreTools.Serialization
Interface = item.ReadString(Models.Internal.Device.InterfaceKey),
};
- if (item.ContainsKey(Models.Internal.Device.InstanceKey) && item[Models.Internal.Device.InstanceKey] is Models.Internal.Instance instance)
- device.Instance = ConvertToListxml(instance);
+ var instance = item.Read(Models.Internal.Device.InstanceKey);
+ device.Instance = ConvertToListxml(instance);
- if (item.ContainsKey(Models.Internal.Device.ExtensionKey) && item[Models.Internal.Device.ExtensionKey] is Models.Internal.Extension[] extensions)
- {
- var extensionItems = new List();
- foreach (var extension in extensions)
- {
- extensionItems.Add(ConvertToListxml(extension));
- }
- device.Extension = extensionItems.ToArray();
- }
+ var extensions = item.Read(Models.Internal.Device.ExtensionKey);
+ device.Extension = extensions?.Select(ConvertToListxml)?.ToArray();
return device;
}
@@ -1188,8 +1081,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.DeviceRef ConvertToListxml(Models.Internal.DeviceRef item)
+ public static Models.Listxml.DeviceRef? ConvertToListxml(Models.Internal.DeviceRef? item)
{
+ if (item == null)
+ return null;
+
var deviceRef = new Models.Listxml.DeviceRef
{
Name = item.ReadString(Models.Internal.DeviceRef.NameKey),
@@ -1200,8 +1096,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.DipLocation ConvertToListxml(Models.Internal.DipLocation item)
+ public static Models.Listxml.DipLocation? ConvertToListxml(Models.Internal.DipLocation? item)
{
+ if (item == null)
+ return null;
+
var dipLocation = new Models.Listxml.DipLocation
{
Name = item.ReadString(Models.Internal.DipLocation.NameKey),
@@ -1214,8 +1113,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.DipSwitch ConvertToListxml(Models.Internal.DipSwitch item)
+ public static Models.Listxml.DipSwitch? ConvertToListxml(Models.Internal.DipSwitch? item)
{
+ if (item == null)
+ return null;
+
var dipSwitch = new Models.Listxml.DipSwitch
{
Name = item.ReadString(Models.Internal.DipSwitch.NameKey),
@@ -1223,28 +1125,14 @@ namespace SabreTools.Serialization
Mask = item.ReadString(Models.Internal.DipSwitch.MaskKey),
};
- if (item.ContainsKey(Models.Internal.DipSwitch.ConditionKey) && item[Models.Internal.DipSwitch.ConditionKey] is Models.Internal.Condition condition)
- dipSwitch.Condition = ConvertToListxml(condition);
+ var condition = item.Read(Models.Internal.DipSwitch.ConditionKey);
+ dipSwitch.Condition = ConvertToListxml(condition);
- if (item.ContainsKey(Models.Internal.DipSwitch.DipLocationKey) && item[Models.Internal.DipSwitch.DipLocationKey] is Models.Internal.DipLocation[] dipLocations)
- {
- var dipLocationItems = new List();
- foreach (var dipLocation in dipLocations)
- {
- dipLocationItems.Add(ConvertToListxml(dipLocation));
- }
- dipSwitch.DipLocation = dipLocationItems.ToArray();
- }
+ var dipLocations = item.Read(Models.Internal.DipSwitch.DipLocationKey);
+ dipSwitch.DipLocation = dipLocations?.Select(ConvertToListxml)?.ToArray();
- if (item.ContainsKey(Models.Internal.DipSwitch.DipValueKey) && item[Models.Internal.DipSwitch.DipValueKey] is Models.Internal.DipValue[] dipValues)
- {
- var dipValueItems = new List();
- foreach (var dipValue in dipValues)
- {
- dipValueItems.Add(ConvertToListxml(dipValue));
- }
- dipSwitch.DipValue = dipValueItems.ToArray();
- }
+ var dipValues = item.Read(Models.Internal.DipSwitch.DipValueKey);
+ dipSwitch.DipValue = dipValues?.Select(ConvertToListxml)?.ToArray();
return dipSwitch;
}
@@ -1252,8 +1140,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.DipValue ConvertToListxml(Models.Internal.DipValue item)
+ public static Models.Listxml.DipValue? ConvertToListxml(Models.Internal.DipValue? item)
{
+ if (item == null)
+ return null;
+
var dipValue = new Models.Listxml.DipValue
{
Name = item.ReadString(Models.Internal.DipValue.NameKey),
@@ -1261,8 +1152,8 @@ namespace SabreTools.Serialization
Default = item.ReadString(Models.Internal.DipValue.DefaultKey),
};
- if (item.ContainsKey(Models.Internal.DipValue.ConditionKey) && item[Models.Internal.DipValue.ConditionKey] is Models.Internal.Condition condition)
- dipValue.Condition = ConvertToListxml(condition);
+ var condition = item.Read(Models.Internal.DipValue.ConditionKey);
+ dipValue.Condition = ConvertToListxml(condition);
return dipValue;
}
@@ -1270,8 +1161,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Disk ConvertToListxml(Models.Internal.Disk item)
+ public static Models.Listxml.Disk? ConvertToListxml(Models.Internal.Disk? item)
{
+ if (item == null)
+ return null;
+
var disk = new Models.Listxml.Disk
{
Name = item.ReadString(Models.Internal.Disk.NameKey),
@@ -1290,8 +1184,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Display ConvertToListxml(Models.Internal.Display item)
+ public static Models.Listxml.Display? ConvertToListxml(Models.Internal.Display? item)
{
+ if (item == null)
+ return null;
+
var display = new Models.Listxml.Display
{
Tag = item.ReadString(Models.Internal.Display.TagKey),
@@ -1315,8 +1212,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Driver ConvertToListxml(Models.Internal.Driver item)
+ public static Models.Listxml.Driver? ConvertToListxml(Models.Internal.Driver? item)
{
+ if (item == null)
+ return null;
+
var driver = new Models.Listxml.Driver
{
Status = item.ReadString(Models.Internal.Driver.StatusKey),
@@ -1337,8 +1237,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Extension ConvertToListxml(Models.Internal.Extension item)
+ public static Models.Listxml.Extension? ConvertToListxml(Models.Internal.Extension? item)
{
+ if (item == null)
+ return null;
+
var extension = new Models.Listxml.Extension
{
Name = item.ReadString(Models.Internal.Extension.NameKey),
@@ -1349,8 +1252,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Feature ConvertToListxml(Models.Internal.Feature item)
+ public static Models.Listxml.Feature? ConvertToListxml(Models.Internal.Feature? item)
{
+ if (item == null)
+ return null;
+
var feature = new Models.Listxml.Feature
{
Type = item.ReadString(Models.Internal.Feature.TypeKey),
@@ -1363,8 +1269,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Input ConvertToListxml(Models.Internal.Input item)
+ public static Models.Listxml.Input? ConvertToListxml(Models.Internal.Input? item)
{
+ if (item == null)
+ return null;
+
var input = new Models.Listxml.Input
{
Service = item.ReadString(Models.Internal.Input.ServiceKey),
@@ -1375,15 +1284,8 @@ namespace SabreTools.Serialization
Coins = item.ReadString(Models.Internal.Input.CoinsKey),
};
- if (item.ContainsKey(Models.Internal.Input.ControlKey) && item[Models.Internal.Input.ControlKey] is Models.Internal.Control[] controls)
- {
- var controlItems = new List();
- foreach (var control in controls)
- {
- controlItems.Add(ConvertToListxml(control));
- }
- input.Control = controlItems.ToArray();
- }
+ var controls = item.Read(Models.Internal.Input.ControlKey);
+ input.Control = controls?.Select(ConvertToListxml)?.ToArray();
return input;
}
@@ -1391,8 +1293,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Instance ConvertToListxml(Models.Internal.Instance item)
+ public static Models.Listxml.Instance? ConvertToListxml(Models.Internal.Instance? item)
{
+ if (item == null)
+ return null;
+
var instance = new Models.Listxml.Instance
{
Name = item.ReadString(Models.Internal.Instance.NameKey),
@@ -1404,31 +1309,30 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Port ConvertToListxml(Models.Internal.Port item)
+ public static Models.Listxml.Port? ConvertToListxml(Models.Internal.Port? item)
{
- var input = new Models.Listxml.Port
+ if (item == null)
+ return null;
+
+ var port = new Models.Listxml.Port
{
Tag = item.ReadString(Models.Internal.Port.TagKey),
};
- if (item.ContainsKey(Models.Internal.Port.AnalogKey) && item[Models.Internal.Port.AnalogKey] is Models.Internal.Analog[] analogs)
- {
- var analogItems = new List();
- foreach (var analog in analogs)
- {
- analogItems.Add(ConvertToListxml(analog));
- }
- input.Analog = analogItems.ToArray();
- }
+ var analogs = item.Read(Models.Internal.Port.AnalogKey);
+ port.Analog = analogs?.Select(ConvertToListxml)?.ToArray();
- return input;
+ return port;
}
///
/// Convert from to
///
- public static Models.Listxml.RamOption ConvertToListxml(Models.Internal.RamOption item)
+ public static Models.Listxml.RamOption? ConvertToListxml(Models.Internal.RamOption? item)
{
+ if (item == null)
+ return null;
+
var ramOption = new Models.Listxml.RamOption
{
Name = item.ReadString(Models.Internal.RamOption.NameKey),
@@ -1440,8 +1344,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Rom ConvertToListxml(Models.Internal.Rom item)
+ public static Models.Listxml.Rom? ConvertToListxml(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var rom = new Models.Listxml.Rom
{
Name = item.ReadString(Models.Internal.Rom.NameKey),
@@ -1463,8 +1370,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Sample ConvertToListxml(Models.Internal.Sample item)
+ public static Models.Listxml.Sample? ConvertToListxml(Models.Internal.Sample? item)
{
+ if (item == null)
+ return null;
+
var sample = new Models.Listxml.Sample
{
Name = item.ReadString(Models.Internal.Sample.NameKey),
@@ -1475,22 +1385,18 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Slot ConvertToListxml(Models.Internal.Slot item)
+ public static Models.Listxml.Slot? ConvertToListxml(Models.Internal.Slot? item)
{
+ if (item == null)
+ return null;
+
var slot = new Models.Listxml.Slot
{
Name = item.ReadString(Models.Internal.Slot.NameKey),
};
- if (item.ContainsKey(Models.Internal.Slot.SlotOptionKey) && item[Models.Internal.Slot.SlotOptionKey] is Models.Internal.SlotOption[] slotOptions)
- {
- var slotOptionItems = new List();
- foreach (var slotOption in slotOptions)
- {
- slotOptionItems.Add(ConvertToListxml(slotOption));
- }
- slot.SlotOption = slotOptionItems.ToArray();
- }
+ var slotOptions = item.Read(Models.Internal.Slot.SlotOptionKey);
+ slot.SlotOption = slotOptions?.Select(ConvertToListxml)?.ToArray();
return slot;
}
@@ -1498,8 +1404,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.SlotOption ConvertToListxml(Models.Internal.SlotOption item)
+ public static Models.Listxml.SlotOption? ConvertToListxml(Models.Internal.SlotOption? item)
{
+ if (item == null)
+ return null;
+
var slotOption = new Models.Listxml.SlotOption
{
Name = item.ReadString(Models.Internal.SlotOption.NameKey),
@@ -1512,8 +1421,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.SoftwareList ConvertToListxml(Models.Internal.SoftwareList item)
+ public static Models.Listxml.SoftwareList? ConvertToListxml(Models.Internal.SoftwareList? item)
{
+ if (item == null)
+ return null;
+
var softwareList = new Models.Listxml.SoftwareList
{
Tag = item.ReadString(Models.Internal.SoftwareList.TagKey),
@@ -1527,8 +1439,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Sound ConvertToListxml(Models.Internal.Sound item)
+ public static Models.Listxml.Sound? ConvertToListxml(Models.Internal.Sound? item)
{
+ if (item == null)
+ return null;
+
var sound = new Models.Listxml.Sound
{
Channels = item.ReadString(Models.Internal.Sound.ChannelsKey),
@@ -1539,8 +1454,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Listxml.Video ConvertToListxml(Models.Internal.Video item)
+ public static Models.Listxml.Video? ConvertToListxml(Models.Internal.Video? item)
{
+ if (item == null)
+ return null;
+
var video = new Models.Listxml.Video
{
Screen = item.ReadString(Models.Internal.Video.ScreenKey),
diff --git a/SabreTools.Serialization/Internal.Logiqx.cs b/SabreTools.Serialization/Internal.Logiqx.cs
index 1a448f70..f21aa8ae 100644
--- a/SabreTools.Serialization/Internal.Logiqx.cs
+++ b/SabreTools.Serialization/Internal.Logiqx.cs
@@ -311,8 +311,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Logiqx.GameBase ConvertMachineToLogiqx(Models.Internal.Machine item, bool game = false)
+ public static Models.Logiqx.GameBase? ConvertMachineToLogiqx(Models.Internal.Machine? item, bool game = false)
{
+ if (item == null)
+ return null;
+
Models.Logiqx.GameBase gameBase = game ? new Models.Logiqx.Game() : new Models.Logiqx.Machine();
gameBase.Name = item.ReadString(Models.Internal.Machine.NameKey);
@@ -335,108 +338,38 @@ namespace SabreTools.Serialization
gameBase.Publisher = item.ReadString(Models.Internal.Machine.PublisherKey);
gameBase.Category = item.ReadStringArray(Models.Internal.Machine.CategoryKey);
- if (item.ContainsKey(Models.Internal.Machine.TruripKey) && item[Models.Internal.Machine.TruripKey] is Models.Logiqx.Trurip trurip)
- gameBase.Trurip = trurip;
+ var trurip = item.Read(Models.Internal.Machine.TruripKey);
+ gameBase.Trurip = trurip;
- if (item.ContainsKey(Models.Internal.Machine.ReleaseKey) && item[Models.Internal.Machine.ReleaseKey] is Models.Internal.Release[] releases)
- {
- var releaseItems = new List();
- foreach (var release in releases)
- {
- releaseItems.Add(ConvertToLogiqx(release));
- }
- gameBase.Release = releaseItems.ToArray();
- }
+ var releases = item.Read(Models.Internal.Machine.ReleaseKey);
+ gameBase.Release = releases?.Select(ConvertToLogiqx)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.BiosSetKey) && item[Models.Internal.Machine.BiosSetKey] is Models.Internal.BiosSet[] biosSets)
- {
- var biosSetItems = new List();
- foreach (var biosSet in biosSets)
- {
- biosSetItems.Add(ConvertToLogiqx(biosSet));
- }
- gameBase.BiosSet = biosSetItems.ToArray();
- }
+ var biosSets = item.Read(Models.Internal.Machine.BiosSetKey);
+ gameBase.BiosSet = biosSets?.Select(ConvertToLogiqx)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.RomKey) && item[Models.Internal.Machine.RomKey] is Models.Internal.Rom[] roms)
- {
- var romItems = new List();
- foreach (var rom in roms)
- {
- romItems.Add(ConvertToLogiqx(rom));
- }
- gameBase.Rom = romItems.ToArray();
- }
+ var roms = item.Read(Models.Internal.Machine.RomKey);
+ gameBase.Rom = roms?.Select(ConvertToLogiqx)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.DiskKey) && item[Models.Internal.Machine.DiskKey] is Models.Internal.Disk[] disks)
- {
- var diskItems = new List();
- foreach (var disk in disks)
- {
- diskItems.Add(ConvertToLogiqx(disk));
- }
- gameBase.Disk = diskItems.ToArray();
- }
+ var disks = item.Read(Models.Internal.Machine.DiskKey);
+ gameBase.Disk = disks?.Select(ConvertToLogiqx)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.MediaKey) && item[Models.Internal.Machine.MediaKey] is Models.Internal.Media[] medias)
- {
- var mediaItems = new List();
- foreach (var media in medias)
- {
- mediaItems.Add(ConvertToLogiqx(media));
- }
- gameBase.Media = mediaItems.ToArray();
- }
+ var medias = item.Read(Models.Internal.Machine.MediaKey);
+ gameBase.Media = medias?.Select(ConvertToLogiqx)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.DeviceRefKey) && item[Models.Internal.Machine.DeviceRefKey] is Models.Internal.DeviceRef[] deviceRefs)
- {
- var deviceRefItems = new List();
- foreach (var deviceRef in deviceRefs)
- {
- deviceRefItems.Add(ConvertToLogiqx(deviceRef));
- }
- gameBase.DeviceRef = deviceRefItems.ToArray();
- }
+ var deviceRefs = item.Read(Models.Internal.Machine.DeviceRefKey);
+ gameBase.DeviceRef = deviceRefs?.Select(ConvertToLogiqx)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.SampleKey) && item[Models.Internal.Machine.SampleKey] is Models.Internal.Sample[] samples)
- {
- var sampleItems = new List();
- foreach (var sample in samples)
- {
- sampleItems.Add(ConvertToLogiqx(sample));
- }
- gameBase.Sample = sampleItems.ToArray();
- }
+ var samples = item.Read(Models.Internal.Machine.SampleKey);
+ gameBase.Sample = samples?.Select(ConvertToLogiqx)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.ArchiveKey) && item[Models.Internal.Machine.ArchiveKey] is Models.Internal.Archive[] archives)
- {
- var archiveItems = new List();
- foreach (var archive in archives)
- {
- archiveItems.Add(ConvertToLogiqx(archive));
- }
- gameBase.Archive = archiveItems.ToArray();
- }
+ var archives = item.Read(Models.Internal.Machine.ArchiveKey);
+ gameBase.Archive = archives?.Select(ConvertToLogiqx)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.DriverKey) && item[Models.Internal.Machine.DriverKey] is Models.Internal.Driver[] drivers)
- {
- var driverItems = new List();
- foreach (var chip in drivers)
- {
- driverItems.Add(ConvertToLogiqx(chip));
- }
- gameBase.Driver = driverItems.ToArray();
- }
+ var drivers = item.Read(Models.Internal.Machine.DriverKey);
+ gameBase.Driver = drivers?.Select(ConvertToLogiqx)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.SoftwareListKey) && item[Models.Internal.Machine.SoftwareListKey] is Models.Internal.SoftwareList[] softwareLists)
- {
- var softwareListItems = new List();
- foreach (var softwareList in softwareLists)
- {
- softwareListItems.Add(ConvertToLogiqx(softwareList));
- }
- gameBase.SoftwareList = softwareListItems.ToArray();
- }
+ var softwareLists = item.Read(Models.Internal.Machine.SoftwareListKey);
+ gameBase.SoftwareList = softwareLists?.Select(ConvertToLogiqx)?.ToArray();
return gameBase;
}
@@ -444,8 +377,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Logiqx.Archive ConvertToLogiqx(Models.Internal.Archive item)
+ public static Models.Logiqx.Archive? ConvertToLogiqx(Models.Internal.Archive? item)
{
+ if (item == null)
+ return null;
+
var archive = new Models.Logiqx.Archive
{
Name = item.ReadString(Models.Internal.Archive.NameKey),
@@ -456,8 +392,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Logiqx.BiosSet ConvertToLogiqx(Models.Internal.BiosSet item)
+ public static Models.Logiqx.BiosSet? ConvertToLogiqx(Models.Internal.BiosSet? item)
{
+ if (item == null)
+ return null;
+
var biosset = new Models.Logiqx.BiosSet
{
Name = item.ReadString(Models.Internal.BiosSet.NameKey),
@@ -470,8 +409,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Logiqx.DeviceRef ConvertToLogiqx(Models.Internal.DeviceRef item)
+ public static Models.Logiqx.DeviceRef? ConvertToLogiqx(Models.Internal.DeviceRef? item)
{
+ if (item == null)
+ return null;
+
var deviceRef = new Models.Logiqx.DeviceRef
{
Name = item.ReadString(Models.Internal.DipSwitch.NameKey),
@@ -482,8 +424,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Logiqx.Disk ConvertToLogiqx(Models.Internal.Disk item)
+ public static Models.Logiqx.Disk? ConvertToLogiqx(Models.Internal.Disk? item)
{
+ if (item == null)
+ return null;
+
var disk = new Models.Logiqx.Disk
{
Name = item.ReadString(Models.Internal.Disk.NameKey),
@@ -499,8 +444,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Logiqx.Driver ConvertToLogiqx(Models.Internal.Driver item)
+ public static Models.Logiqx.Driver? ConvertToLogiqx(Models.Internal.Driver? item)
{
+ if (item == null)
+ return null;
+
var driver = new Models.Logiqx.Driver
{
Status = item.ReadString(Models.Internal.Driver.StatusKey),
@@ -518,8 +466,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Logiqx.Media ConvertToLogiqx(Models.Internal.Media item)
+ public static Models.Logiqx.Media? ConvertToLogiqx(Models.Internal.Media? item)
{
+ if (item == null)
+ return null;
+
var media = new Models.Logiqx.Media
{
Name = item.ReadString(Models.Internal.Media.NameKey),
@@ -534,8 +485,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Logiqx.Release ConvertToLogiqx(Models.Internal.Release item)
+ public static Models.Logiqx.Release? ConvertToLogiqx(Models.Internal.Release? item)
{
+ if (item == null)
+ return null;
+
var release = new Models.Logiqx.Release
{
Name = item.ReadString(Models.Internal.Release.NameKey),
@@ -550,8 +504,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Logiqx.Rom ConvertToLogiqx(Models.Internal.Rom item)
+ public static Models.Logiqx.Rom? ConvertToLogiqx(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var rom = new Models.Logiqx.Rom
{
Name = item.ReadString(Models.Internal.Rom.NameKey),
@@ -579,8 +536,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Logiqx.Sample ConvertToLogiqx(Models.Internal.Sample item)
+ public static Models.Logiqx.Sample? ConvertToLogiqx(Models.Internal.Sample? item)
{
+ if (item == null)
+ return null;
+
var sample = new Models.Logiqx.Sample
{
Name = item.ReadString(Models.Internal.Sample.NameKey),
@@ -591,8 +551,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.Logiqx.SoftwareList ConvertToLogiqx(Models.Internal.SoftwareList item)
+ public static Models.Logiqx.SoftwareList? ConvertToLogiqx(Models.Internal.SoftwareList? item)
{
+ if (item == null)
+ return null;
+
var softwareList = new Models.Logiqx.SoftwareList
{
Tag = item.ReadString(Models.Internal.SoftwareList.TagKey),
diff --git a/SabreTools.Serialization/Internal.OfflineList.cs b/SabreTools.Serialization/Internal.OfflineList.cs
index 45880d02..b073f140 100644
--- a/SabreTools.Serialization/Internal.OfflineList.cs
+++ b/SabreTools.Serialization/Internal.OfflineList.cs
@@ -79,8 +79,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.OfflineList.Game ConvertMachineToOfflineList(Models.Internal.Machine item)
+ public static Models.OfflineList.Game? ConvertMachineToOfflineList(Models.Internal.Machine? item)
{
+ if (item == null)
+ return null;
+
var game = new Models.OfflineList.Game
{
ImageNumber = item.ReadString(Models.Internal.Machine.ImageNumberKey),
@@ -97,16 +100,12 @@ namespace SabreTools.Serialization
DuplicateID = item.ReadString(Models.Internal.Machine.DuplicateIDKey),
};
- if (item.ContainsKey(Models.Internal.Machine.RomKey) && item[Models.Internal.Machine.RomKey] is Models.Internal.Rom[] roms)
- {
- var romCRCItems = new List();
- foreach (var rom in roms)
- {
- game.RomSize ??= rom.ReadString(Models.Internal.Rom.SizeKey);
- romCRCItems.Add(ConvertToOfflineList(rom));
- }
- game.Files = new Models.OfflineList.Files { RomCRC = romCRCItems.ToArray() };
- }
+ var roms = item.Read(Models.Internal.Machine.RomKey);
+ game.RomSize = roms?
+ .Select(rom => rom.ReadString(Models.Internal.Rom.SizeKey))?
+ .FirstOrDefault(s => s != null);
+ var romCRCs = roms?.Select(ConvertToOfflineList).ToArray();
+ game.Files = new Models.OfflineList.Files { RomCRC = romCRCs };
return game;
}
@@ -114,8 +113,11 @@ namespace SabreTools.Serialization
///
/// Convert from an array of to
///
- public static Models.OfflineList.Files ConvertToOfflineList(Models.Internal.Rom[] items)
+ public static Models.OfflineList.Files? ConvertToOfflineList(Models.Internal.Rom[]? items)
{
+ if (items == null)
+ return null;
+
var romCRCs = new List();
foreach (var item in items)
{
@@ -127,8 +129,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.OfflineList.FileRomCRC ConvertToOfflineList(Models.Internal.Rom item)
+ public static Models.OfflineList.FileRomCRC? ConvertToOfflineList(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var fileRomCRC = new Models.OfflineList.FileRomCRC
{
Extension = item.ReadString(Models.Internal.Rom.ExtensionKey),
diff --git a/SabreTools.Serialization/Internal.OpenMSX.cs b/SabreTools.Serialization/Internal.OpenMSX.cs
index 39d5ed35..df220ec5 100644
--- a/SabreTools.Serialization/Internal.OpenMSX.cs
+++ b/SabreTools.Serialization/Internal.OpenMSX.cs
@@ -101,8 +101,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.OpenMSX.Software ConvertMachineToOpenMSX(Models.Internal.Machine item)
+ public static Models.OpenMSX.Software? ConvertMachineToOpenMSX(Models.Internal.Machine? item)
{
+ if (item == null)
+ return null;
+
var game = new Models.OpenMSX.Software
{
Title = item.ReadString(Models.Internal.Machine.NameKey),
@@ -113,15 +116,8 @@ namespace SabreTools.Serialization
Country = item.ReadString(Models.Internal.Machine.CountryKey),
};
- if (item.ContainsKey(Models.Internal.Machine.DumpKey) && item[Models.Internal.Machine.DumpKey] is Models.Internal.Dump[] dumps)
- {
- var dumpItems = new List();
- foreach (var dump in dumps)
- {
- dumpItems.Add(ConvertToOpenMSX(dump));
- }
- game.Dump = dumpItems.ToArray();
- }
+ var dumps = item.Read(Models.Internal.Machine.DumpKey);
+ game.Dump = dumps?.Select(ConvertToOpenMSX)?.ToArray();
return game;
}
@@ -129,25 +125,24 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.OpenMSX.Dump ConvertToOpenMSX(Models.Internal.Dump item)
+ public static Models.OpenMSX.Dump? ConvertToOpenMSX(Models.Internal.Dump? item)
{
+ if (item == null)
+ return null;
+
var dump = new Models.OpenMSX.Dump();
- if (item.ContainsKey(Models.Internal.Dump.OriginalKey) && item[Models.Internal.Dump.OriginalKey] is Models.Internal.Original original)
- dump.Original = ConvertToOpenMSX(original);
+ var original = item.Read(Models.Internal.Dump.OriginalKey);
+ dump.Original = ConvertToOpenMSX(original);
- if (item.ContainsKey(Models.Internal.Dump.RomKey) && item[Models.Internal.Dump.RomKey] is Models.Internal.Rom rom)
- {
- dump.Rom = ConvertToOpenMSXRom(rom);
- }
- else if (item.ContainsKey(Models.Internal.Dump.MegaRomKey) && item[Models.Internal.Dump.MegaRomKey] is Models.Internal.Rom megaRom)
- {
- dump.Rom = ConvertToOpenMSXMegaRom(megaRom);
- }
- else if (item.ContainsKey(Models.Internal.Dump.SCCPlusCartKey) && item[Models.Internal.Dump.SCCPlusCartKey] is Models.Internal.Rom sccPlusCart)
- {
- dump.Rom = ConvertToOpenMSXSCCPlusCart(sccPlusCart);
- }
+ var rom = item.Read(Models.Internal.Dump.RomKey);
+ dump.Rom = ConvertToOpenMSXRom(rom);
+
+ var megaRom = item.Read(Models.Internal.Dump.MegaRomKey);
+ dump.Rom = ConvertToOpenMSXRom(megaRom);
+
+ var sccPlusCart = item.Read(Models.Internal.Dump.SCCPlusCartKey);
+ dump.Rom = ConvertToOpenMSXRom(sccPlusCart);
return dump;
}
@@ -155,8 +150,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.OpenMSX.MegaRom ConvertToOpenMSXMegaRom(Models.Internal.Rom item)
+ public static Models.OpenMSX.MegaRom? ConvertToOpenMSXMegaRom(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var megaRom = new Models.OpenMSX.MegaRom
{
Start = item.ReadString(Models.Internal.Rom.StartKey),
@@ -170,8 +168,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.OpenMSX.Original ConvertToOpenMSX(Models.Internal.Original item)
+ public static Models.OpenMSX.Original? ConvertToOpenMSX(Models.Internal.Original? item)
{
+ if (item == null)
+ return null;
+
var original = new Models.OpenMSX.Original
{
Value = item.ReadString(Models.Internal.Original.ValueKey),
@@ -183,8 +184,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.OpenMSX.Rom ConvertToOpenMSXRom(Models.Internal.Rom item)
+ public static Models.OpenMSX.Rom? ConvertToOpenMSXRom(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var rom = new Models.OpenMSX.Rom
{
Start = item.ReadString(Models.Internal.Rom.StartKey),
@@ -198,8 +202,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.OpenMSX.SCCPlusCart ConvertToOpenMSXSCCPlusCart(Models.Internal.Rom item)
+ public static Models.OpenMSX.SCCPlusCart? ConvertToOpenMSXSCCPlusCart(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var sccPlusCart = new Models.OpenMSX.SCCPlusCart
{
Start = item.ReadString(Models.Internal.Rom.StartKey),
diff --git a/SabreTools.Serialization/Internal.RomCenter.cs b/SabreTools.Serialization/Internal.RomCenter.cs
index 85a3a569..4a4ca189 100644
--- a/SabreTools.Serialization/Internal.RomCenter.cs
+++ b/SabreTools.Serialization/Internal.RomCenter.cs
@@ -1,4 +1,3 @@
-using System.Collections.Generic;
using System.Linq;
namespace SabreTools.Serialization
@@ -49,39 +48,34 @@ namespace SabreTools.Serialization
///
/// Convert from to an array of
///
- public static Models.RomCenter.Rom[] ConvertMachineToRomCenter(Models.Internal.Machine item)
+ public static Models.RomCenter.Rom?[]? ConvertMachineToRomCenter(Models.Internal.Machine? item)
{
- var romItems = new List();
+ if (item == null)
+ return null;
- if (item.ContainsKey(Models.Internal.Machine.RomKey) && item[Models.Internal.Machine.RomKey] is Models.Internal.Rom[] roms)
- {
- foreach (var rom in roms)
- {
- var romItem = ConvertToRomCenter(rom);
-
- romItem.ParentName = rom.ReadString(Models.Internal.Machine.RomOfKey);
- //romItem.ParentDescription = rom.ReadString(Models.Internal.Machine.RomOfKey); // This is unmappable
- romItem.GameName = rom.ReadString(Models.Internal.Machine.NameKey);
- romItem.GameDescription = rom.ReadString(Models.Internal.Machine.DescriptionKey);
-
- romItems.Add(romItem);
- }
- }
-
- return romItems.ToArray();
+ var roms = item.Read(Models.Internal.Machine.RomKey);
+ return roms?.Select(rom => ConvertToRomCenter(rom, item))?.ToArray();
}
///
/// Convert from to
///
- public static Models.RomCenter.Rom ConvertToRomCenter(Models.Internal.Rom item)
+ public static Models.RomCenter.Rom? ConvertToRomCenter(Models.Internal.Rom? item, Models.Internal.Machine? parent)
{
+ if (item == null)
+ return null;
+
var row = new Models.RomCenter.Rom
{
RomName = item.ReadString(Models.Internal.Rom.NameKey),
RomCRC = item.ReadString(Models.Internal.Rom.CRCKey),
RomSize = item.ReadString(Models.Internal.Rom.SizeKey),
MergeName = item.ReadString(Models.Internal.Rom.MergeKey),
+
+ ParentName = parent?.ReadString(Models.Internal.Machine.RomOfKey),
+ //ParentDescription = parent?.ReadString(Models.Internal.Machine.ParentDescriptionKey), // This is unmappable
+ GameName = parent?.ReadString(Models.Internal.Machine.NameKey),
+ GameDescription = parent?.ReadString(Models.Internal.Machine.DescriptionKey),
};
return row;
}
diff --git a/SabreTools.Serialization/Internal.SeparatedValue.cs b/SabreTools.Serialization/Internal.SeparatedValue.cs
index af5a2859..55f84909 100644
--- a/SabreTools.Serialization/Internal.SeparatedValue.cs
+++ b/SabreTools.Serialization/Internal.SeparatedValue.cs
@@ -31,7 +31,7 @@ namespace SabreTools.Serialization
case Models.Internal.Media media:
machine[Models.Internal.Machine.MediaKey] = new Models.Internal.Media[] { media };
break;
-
+
case Models.Internal.Rom rom:
machine[Models.Internal.Machine.RomKey] = new Models.Internal.Rom[] { rom };
break;
@@ -86,42 +86,24 @@ namespace SabreTools.Serialization
///
/// Convert from to an array of
///
- public static Models.SeparatedValue.Row[] ConvertMachineToSeparatedValue(Models.Internal.Machine item)
+ public static Models.SeparatedValue.Row[]? ConvertMachineToSeparatedValue(Models.Internal.Machine? item)
{
+ if (item == null)
+ return null;
+
var rowItems = new List();
- if (item.ContainsKey(Models.Internal.Machine.DiskKey) && item[Models.Internal.Machine.DiskKey] is Models.Internal.Disk[] disks)
- {
- foreach (var disk in disks)
- {
- var rowItem = ConvertToSeparatedValue(disk);
- rowItem.GameName = item.ReadString(Models.Internal.Machine.NameKey);
- rowItem.Description = item.ReadString(Models.Internal.Machine.DescriptionKey);
- rowItems.Add(rowItem);
- }
- }
+ var disks = item.Read(Models.Internal.Machine.DiskKey);
+ if (disks != null)
+ rowItems.AddRange(disks.Select(disk => ConvertToSeparatedValue(disk, item)));
- if (item.ContainsKey(Models.Internal.Machine.MediaKey) && item[Models.Internal.Machine.MediaKey] is Models.Internal.Media[] media)
- {
- foreach (var medium in media)
- {
- var rowItem = ConvertToSeparatedValue(medium);
- rowItem.GameName = item.ReadString(Models.Internal.Machine.NameKey);
- rowItem.Description = item.ReadString(Models.Internal.Machine.DescriptionKey);
- rowItems.Add(rowItem);
- }
- }
+ var media = item.Read(Models.Internal.Machine.MediaKey);
+ if (media != null)
+ rowItems.AddRange(media.Select(medium => ConvertToSeparatedValue(medium, item)));
- if (item.ContainsKey(Models.Internal.Machine.RomKey) && item[Models.Internal.Machine.RomKey] is Models.Internal.Rom[] roms)
- {
- foreach (var rom in roms)
- {
- var rowItem = ConvertToSeparatedValue(rom);
- rowItem.GameName = item.ReadString(Models.Internal.Machine.NameKey);
- rowItem.Description = item.ReadString(Models.Internal.Machine.DescriptionKey);
- rowItems.Add(rowItem);
- }
- }
+ var roms = item.Read(Models.Internal.Machine.RomKey);
+ if (roms != null)
+ rowItems.AddRange(roms.Select(rom => ConvertToSeparatedValue(rom, item)));
return rowItems.ToArray();
}
@@ -129,10 +111,15 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SeparatedValue.Row ConvertToSeparatedValue(Models.Internal.Disk item)
+ public static Models.SeparatedValue.Row? ConvertToSeparatedValue(Models.Internal.Disk? item, Models.Internal.Machine? parent)
{
+ if (item == null)
+ return null;
+
var row = new Models.SeparatedValue.Row
{
+ GameName = parent?.ReadString(Models.Internal.Machine.NameKey),
+ Description = parent?.ReadString(Models.Internal.Machine.DescriptionKey),
Type = "disk",
DiskName = item.ReadString(Models.Internal.Disk.NameKey),
MD5 = item.ReadString(Models.Internal.Disk.MD5Key),
@@ -145,10 +132,15 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SeparatedValue.Row ConvertToSeparatedValue(Models.Internal.Media item)
+ public static Models.SeparatedValue.Row? ConvertToSeparatedValue(Models.Internal.Media? item, Models.Internal.Machine? parent)
{
+ if (item == null)
+ return null;
+
var row = new Models.SeparatedValue.Row
{
+ GameName = parent?.ReadString(Models.Internal.Machine.NameKey),
+ Description = parent?.ReadString(Models.Internal.Machine.DescriptionKey),
Type = "media",
DiskName = item.ReadString(Models.Internal.Media.NameKey),
MD5 = item.ReadString(Models.Internal.Media.MD5Key),
@@ -162,10 +154,15 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SeparatedValue.Row ConvertToSeparatedValue(Models.Internal.Rom item)
+ public static Models.SeparatedValue.Row? ConvertToSeparatedValue(Models.Internal.Rom? item, Models.Internal.Machine? parent)
{
+ if (item == null)
+ return null;
+
var row = new Models.SeparatedValue.Row
{
+ GameName = parent?.ReadString(Models.Internal.Machine.NameKey),
+ Description = parent?.ReadString(Models.Internal.Machine.DescriptionKey),
Type = "rom",
RomName = item.ReadString(Models.Internal.Rom.NameKey),
Size = item.ReadString(Models.Internal.Rom.SizeKey),
diff --git a/SabreTools.Serialization/Internal.SoftwareList.cs b/SabreTools.Serialization/Internal.SoftwareList.cs
index 5c9aaa73..1ba6fbe4 100644
--- a/SabreTools.Serialization/Internal.SoftwareList.cs
+++ b/SabreTools.Serialization/Internal.SoftwareList.cs
@@ -283,8 +283,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SoftwareList.Software ConvertMachineToSoftwareList(Models.Internal.Machine item)
+ public static Models.SoftwareList.Software? ConvertMachineToSoftwareList(Models.Internal.Machine? item)
{
+ if (item == null)
+ return null;
+
var software = new Models.SoftwareList.Software
{
Name = item.ReadString(Models.Internal.Machine.NameKey),
@@ -296,35 +299,14 @@ namespace SabreTools.Serialization
Notes = item.ReadString(Models.Internal.Machine.NotesKey),
};
- if (item.ContainsKey(Models.Internal.Machine.InfoKey) && item[Models.Internal.Machine.InfoKey] is Models.Internal.Info[] infos)
- {
- var infoItems = new List();
- foreach (var info in infos)
- {
- infoItems.Add(ConvertToSoftwareList(info));
- }
- software.Info = infoItems.ToArray();
- }
+ var infos = item.Read(Models.Internal.Machine.InfoKey);
+ software.Info = infos?.Select(ConvertToSoftwareList)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.SharedFeatKey) && item[Models.Internal.Machine.SharedFeatKey] is Models.Internal.SharedFeat[] sharedFeats)
- {
- var sharedFeatItems = new List();
- foreach (var sharedFeat in sharedFeats)
- {
- sharedFeatItems.Add(ConvertToSoftwareList(sharedFeat));
- }
- software.SharedFeat = sharedFeatItems.ToArray();
- }
+ var sharedFeats = item.Read(Models.Internal.Machine.SharedFeatKey);
+ software.SharedFeat = sharedFeats?.Select(ConvertToSoftwareList)?.ToArray();
- if (item.ContainsKey(Models.Internal.Machine.PartKey) && item[Models.Internal.Machine.PartKey] is Models.Internal.Part[] parts)
- {
- var partItems = new List();
- foreach (var part in parts)
- {
- partItems.Add(ConvertToSoftwareList(part));
- }
- software.Part = partItems.ToArray();
- }
+ var parts = item.Read(Models.Internal.Machine.PartKey);
+ software.Part = parts?.Select(ConvertToSoftwareList)?.ToArray();
return software;
}
@@ -332,8 +314,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SoftwareList.DataArea ConvertToSoftwareList(Models.Internal.DataArea item)
+ public static Models.SoftwareList.DataArea? ConvertToSoftwareList(Models.Internal.DataArea? item)
{
+ if (item == null)
+ return null;
+
var dataArea = new Models.SoftwareList.DataArea
{
Name = item.ReadString(Models.Internal.DataArea.NameKey),
@@ -342,15 +327,8 @@ namespace SabreTools.Serialization
Endianness = item.ReadString(Models.Internal.DataArea.EndiannessKey),
};
- if (item.ContainsKey(Models.Internal.DataArea.RomKey) && item[Models.Internal.DataArea.RomKey] is Models.Internal.Rom[] roms)
- {
- var romItems = new List();
- foreach (var rom in roms)
- {
- romItems.Add(ConvertToSoftwareList(rom));
- }
- dataArea.Rom = romItems.ToArray();
- }
+ var roms = item.Read(Models.Internal.DataArea.RomKey);
+ dataArea.Rom = roms?.Select(ConvertToSoftwareList)?.ToArray();
return dataArea;
}
@@ -358,8 +336,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SoftwareList.DipSwitch ConvertToSoftwareList(Models.Internal.DipSwitch item)
+ public static Models.SoftwareList.DipSwitch? ConvertToSoftwareList(Models.Internal.DipSwitch? item)
{
+ if (item == null)
+ return null;
+
var dipSwitch = new Models.SoftwareList.DipSwitch
{
Name = item.ReadString(Models.Internal.DipSwitch.NameKey),
@@ -367,15 +348,8 @@ namespace SabreTools.Serialization
Mask = item.ReadString(Models.Internal.DipSwitch.MaskKey),
};
- if (item.ContainsKey(Models.Internal.DipSwitch.DipValueKey) && item[Models.Internal.DipSwitch.DipValueKey] is Models.Internal.DipValue[] dipValues)
- {
- var dipValueItems = new List();
- foreach (var rom in dipValues)
- {
- dipValueItems.Add(ConvertToSoftwareList(rom));
- }
- dipSwitch.DipValue = dipValueItems.ToArray();
- }
+ var dipValues = item.Read(Models.Internal.DipSwitch.DipValueKey);
+ dipSwitch.DipValue = dipValues?.Select(ConvertToSoftwareList)?.ToArray();
return dipSwitch;
}
@@ -383,8 +357,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SoftwareList.DipValue ConvertToSoftwareList(Models.Internal.DipValue item)
+ public static Models.SoftwareList.DipValue? ConvertToSoftwareList(Models.Internal.DipValue? item)
{
+ if (item == null)
+ return null;
+
var dipValue = new Models.SoftwareList.DipValue
{
Name = item.ReadString(Models.Internal.DipValue.NameKey),
@@ -397,8 +374,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SoftwareList.Disk ConvertToSoftwareList(Models.Internal.Disk item)
+ public static Models.SoftwareList.Disk? ConvertToSoftwareList(Models.Internal.Disk? item)
{
+ if (item == null)
+ return null;
+
var disk = new Models.SoftwareList.Disk
{
Name = item.ReadString(Models.Internal.Disk.NameKey),
@@ -413,22 +393,18 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SoftwareList.DiskArea ConvertToSoftwareList(Models.Internal.DiskArea item)
+ public static Models.SoftwareList.DiskArea? ConvertToSoftwareList(Models.Internal.DiskArea? item)
{
+ if (item == null)
+ return null;
+
var diskArea = new Models.SoftwareList.DiskArea
{
Name = item.ReadString(Models.Internal.DiskArea.NameKey),
};
- if (item.ContainsKey(Models.Internal.DiskArea.DiskKey) && item[Models.Internal.DiskArea.DiskKey] is Models.Internal.Disk[] disks)
- {
- var diskItems = new List();
- foreach (var disk in disks)
- {
- diskItems.Add(ConvertToSoftwareList(disk));
- }
- diskArea.Disk = diskItems.ToArray();
- }
+ var disks = item.Read(Models.Internal.DiskArea.DiskKey);
+ diskArea.Disk = disks?.Select(ConvertToSoftwareList)?.ToArray();
return diskArea;
}
@@ -436,8 +412,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SoftwareList.Feature ConvertToSoftwareList(Models.Internal.Feature item)
+ public static Models.SoftwareList.Feature? ConvertToSoftwareList(Models.Internal.Feature? item)
{
+ if (item == null)
+ return null;
+
var feature = new Models.SoftwareList.Feature
{
Name = item.ReadString(Models.Internal.Feature.NameKey),
@@ -449,8 +428,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SoftwareList.Info ConvertToSoftwareList(Models.Internal.Info item)
+ public static Models.SoftwareList.Info? ConvertToSoftwareList(Models.Internal.Info? item)
{
+ if (item == null)
+ return null;
+
var info = new Models.SoftwareList.Info
{
Name = item.ReadString(Models.Internal.Info.NameKey),
@@ -462,53 +444,28 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SoftwareList.Part ConvertToSoftwareList(Models.Internal.Part item)
+ public static Models.SoftwareList.Part? ConvertToSoftwareList(Models.Internal.Part? item)
{
+ if (item == null)
+ return null;
+
var part = new Models.SoftwareList.Part
{
Name = item.ReadString(Models.Internal.Part.NameKey),
Interface = item.ReadString(Models.Internal.Part.InterfaceKey),
};
- if (item.ContainsKey(Models.Internal.Part.FeatureKey) && item[Models.Internal.Part.FeatureKey] is Models.Internal.Feature[] features)
- {
- var featureItems = new List();
- foreach (var feature in features)
- {
- featureItems.Add(ConvertToSoftwareList(feature));
- }
- part.Feature = featureItems.ToArray();
- }
+ var features = item.Read(Models.Internal.Part.FeatureKey);
+ part.Feature = features?.Select(ConvertToSoftwareList)?.ToArray();
- if (item.ContainsKey(Models.Internal.Part.DataAreaKey) && item[Models.Internal.Part.DataAreaKey] is Models.Internal.DataArea[] dataAreas)
- {
- var dataAreaItems = new List();
- foreach (var dataArea in dataAreas)
- {
- dataAreaItems.Add(ConvertToSoftwareList(dataArea));
- }
- part.DataArea = dataAreaItems.ToArray();
- }
+ var dataAreas = item.Read(Models.Internal.Part.DataAreaKey);
+ part.DataArea = dataAreas?.Select(ConvertToSoftwareList)?.ToArray();
- if (item.ContainsKey(Models.Internal.Part.DiskAreaKey) && item[Models.Internal.Part.DiskAreaKey] is Models.Internal.DiskArea[] diskAreas)
- {
- var diskAreaItems = new List();
- foreach (var diskArea in diskAreas)
- {
- diskAreaItems.Add(ConvertToSoftwareList(diskArea));
- }
- part.DiskArea = diskAreaItems.ToArray();
- }
+ var diskAreas = item.Read(Models.Internal.Part.DiskAreaKey);
+ part.DiskArea = diskAreas?.Select(ConvertToSoftwareList)?.ToArray();
- if (item.ContainsKey(Models.Internal.Part.DipSwitchKey) && item[Models.Internal.Part.DipSwitchKey] is Models.Internal.DipSwitch[] dipSwitches)
- {
- var dipSwitchItems = new List();
- foreach (var rom in dipSwitches)
- {
- dipSwitchItems.Add(ConvertToSoftwareList(rom));
- }
- part.DipSwitch = dipSwitchItems.ToArray();
- }
+ var dipSwitches = item.Read(Models.Internal.Part.DipSwitchKey);
+ part.DipSwitch = dipSwitches?.Select(ConvertToSoftwareList)?.ToArray();
return part;
}
@@ -516,8 +473,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SoftwareList.Rom ConvertToSoftwareList(Models.Internal.Rom item)
+ public static Models.SoftwareList.Rom? ConvertToSoftwareList(Models.Internal.Rom? item)
{
+ if (item == null)
+ return null;
+
var rom = new Models.SoftwareList.Rom
{
Name = item.ReadString(Models.Internal.Rom.NameKey),
@@ -536,8 +496,11 @@ namespace SabreTools.Serialization
///
/// Convert from to
///
- public static Models.SoftwareList.SharedFeat ConvertToSoftwareList(Models.Internal.SharedFeat item)
+ public static Models.SoftwareList.SharedFeat? ConvertToSoftwareList(Models.Internal.SharedFeat? item)
{
+ if (item == null)
+ return null;
+
var sharedFeat = new Models.SoftwareList.SharedFeat
{
Name = item.ReadString(Models.Internal.SharedFeat.NameKey),