using System.Linq; namespace SabreTools.Serialization { /// /// Serializer for RomCenter models to internal structure /// public partial class Internal { #region Serialize /// /// Convert from to /// public static Models.Internal.Machine ConvertMachineFromRomCenter(Models.RomCenter.Rom item) { var machine = new Models.Internal.Machine { [Models.Internal.Machine.RomOfKey] = item.ParentName, //[Models.Internal.Machine.RomOfKey] = item.ParentDescription, // This is unmappable [Models.Internal.Machine.NameKey] = item.GameName, [Models.Internal.Machine.DescriptionKey] = item.GameDescription, [Models.Internal.Machine.RomKey] = new Models.Internal.Rom[] { ConvertFromRomCenter(item) }, }; return machine; } /// /// Convert from to /// public static Models.Internal.Rom ConvertFromRomCenter(Models.RomCenter.Rom item) { var rom = new Models.Internal.Rom { [Models.Internal.Rom.NameKey] = item.RomName, [Models.Internal.Rom.CRCKey] = item.RomCRC, [Models.Internal.Rom.SizeKey] = item.RomSize, [Models.Internal.Rom.MergeKey] = item.MergeName, }; return rom; } #endregion #region Deserialize /// /// Convert from to an array of /// public static Models.RomCenter.Rom?[]? ConvertMachineToRomCenter(Models.Internal.Machine? item) { if (item == null) return null; var roms = item.Read(Models.Internal.Machine.RomKey); return roms?.Select(rom => ConvertToRomCenter(rom, item))?.ToArray(); } /// /// Convert from to /// private 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; } #endregion } }