Reduce enum overhead in metadata

This commit is contained in:
Matt Nadareski
2026-03-26 22:51:14 -04:00
parent 29620c0c4f
commit 8de1fbc52f
38 changed files with 2022 additions and 2370 deletions

View File

@@ -2,183 +2,6 @@ using System;
namespace SabreTools.Metadata.DatItems
{
/// <summary>
/// Determine the chip type
/// </summary>
[Flags]
public enum ChipType
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("cpu")]
CPU = 1 << 0,
[Mapping("audio")]
Audio = 1 << 1,
}
/// <summary>
/// Determine the control type
/// </summary>
[Flags]
public enum ControlType
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("joy")]
Joy = 1 << 0,
[Mapping("stick")]
Stick = 1 << 1,
[Mapping("paddle")]
Paddle = 1 << 2,
[Mapping("pedal")]
Pedal = 1 << 3,
[Mapping("lightgun")]
Lightgun = 1 << 4,
[Mapping("positional")]
Positional = 1 << 5,
[Mapping("dial")]
Dial = 1 << 6,
[Mapping("trackball")]
Trackball = 1 << 7,
[Mapping("mouse")]
Mouse = 1 << 8,
[Mapping("only_buttons")]
OnlyButtons = 1 << 9,
[Mapping("keypad")]
Keypad = 1 << 10,
[Mapping("keyboard")]
Keyboard = 1 << 11,
[Mapping("mahjong")]
Mahjong = 1 << 12,
[Mapping("hanafuda")]
Hanafuda = 1 << 13,
[Mapping("gambling")]
Gambling = 1 << 14,
}
/// <summary>
/// Determine the device type
/// </summary>
[Flags]
public enum DeviceType
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("unknown")]
Unknown = 1 << 0,
[Mapping("cartridge")]
Cartridge = 1 << 1,
[Mapping("floppydisk")]
FloppyDisk = 1 << 2,
[Mapping("harddisk")]
HardDisk = 1 << 3,
[Mapping("cylinder")]
Cylinder = 1 << 4,
[Mapping("cassette")]
Cassette = 1 << 5,
[Mapping("punchcard")]
PunchCard = 1 << 6,
[Mapping("punchtape")]
PunchTape = 1 << 7,
[Mapping("printout")]
Printout = 1 << 8,
[Mapping("serial")]
Serial = 1 << 9,
[Mapping("parallel")]
Parallel = 1 << 10,
[Mapping("snapshot")]
Snapshot = 1 << 11,
[Mapping("quickload")]
QuickLoad = 1 << 12,
[Mapping("memcard")]
MemCard = 1 << 13,
[Mapping("cdrom")]
CDROM = 1 << 14,
[Mapping("magtape")]
MagTape = 1 << 15,
[Mapping("romimage")]
ROMImage = 1 << 16,
[Mapping("midiin")]
MIDIIn = 1 << 17,
[Mapping("midiout")]
MIDIOut = 1 << 18,
[Mapping("picture")]
Picture = 1 << 19,
[Mapping("vidfile")]
VidFile = 1 << 20,
}
/// <summary>
/// Determine the display type
/// </summary>
[Flags]
public enum DisplayType
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("raster")]
Raster = 1 << 0,
[Mapping("vector")]
Vector = 1 << 1,
[Mapping("lcd")]
LCD = 1 << 2,
[Mapping("svg")]
SVG = 1 << 3,
[Mapping("unknown")]
Unknown = 1 << 4,
}
/// <summary>
/// Determines which type of duplicate a file is
/// </summary>
@@ -194,96 +17,6 @@ namespace SabreTools.Metadata.DatItems
External = 1 << 3,
}
/// <summary>
/// Determine the endianness
/// </summary>
[Flags]
public enum Endianness
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("big")]
Big = 1 << 0,
[Mapping("little")]
Little = 1 << 1,
}
/// <summary>
/// Determine the emulation status
/// </summary>
[Flags]
public enum FeatureStatus
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("unemulated")]
Unemulated = 1 << 0,
[Mapping("imperfect")]
Imperfect = 1 << 1,
}
/// <summary>
/// Determine the feature type
/// </summary>
[Flags]
public enum FeatureType
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("protection")]
Protection = 1 << 0,
[Mapping("palette")]
Palette = 1 << 1,
[Mapping("graphics")]
Graphics = 1 << 2,
[Mapping("sound")]
Sound = 1 << 3,
[Mapping("controls")]
Controls = 1 << 4,
[Mapping("keyboard")]
Keyboard = 1 << 5,
[Mapping("mouse")]
Mouse = 1 << 6,
[Mapping("microphone")]
Microphone = 1 << 7,
[Mapping("camera")]
Camera = 1 << 8,
[Mapping("disk")]
Disk = 1 << 9,
[Mapping("printer")]
Printer = 1 << 10,
[Mapping("lan")]
Lan = 1 << 11,
[Mapping("wan")]
Wan = 1 << 12,
[Mapping("timing")]
Timing = 1 << 13,
}
/// <summary>
/// A subset of fields that can be used as keys
/// </summary>
@@ -308,33 +41,6 @@ namespace SabreTools.Metadata.DatItems
SpamSum,
}
/// <summary>
/// Determine the status of the item
/// </summary>
[Flags]
public enum ItemStatus
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("none", "no")]
None = 1 << 0,
[Mapping("good")]
Good = 1 << 1,
[Mapping("baddump")]
BadDump = 1 << 2,
[Mapping("nodump", "yes")]
Nodump = 1 << 3,
[Mapping("verified")]
Verified = 1 << 4,
}
/// <summary>
/// Determine what type of file an item is
/// </summary>
@@ -347,341 +53,157 @@ namespace SabreTools.Metadata.DatItems
// "Actionable" item types
[Mapping("rom")]
/// <summary>"rom"</summary>
Rom,
[Mapping("disk")]
/// <summary>"disk"</summary>
Disk,
[Mapping("file")]
/// <summary>"file"</summary>
File,
[Mapping("media")]
/// <summary>"media"</summary>
Media,
// "Auxiliary" item types
[Mapping("adjuster")]
/// <summary>"adjuster"</summary>
Adjuster,
[Mapping("analog")]
/// <summary>"analog"</summary>
Analog,
[Mapping("archive")]
/// <summary>"archive"</summary>
Archive,
[Mapping("biosset")]
/// <summary>"biosset"</summary>
BiosSet,
[Mapping("chip")]
/// <summary>"chip"</summary>
Chip,
[Mapping("condition")]
/// <summary>"condition"</summary>
Condition,
[Mapping("configuration")]
/// <summary>"configuration"</summary>
Configuration,
[Mapping("conflocation")]
/// <summary>"conflocation"</summary>
ConfLocation,
[Mapping("confsetting")]
/// <summary>"confsetting"</summary>
ConfSetting,
[Mapping("control")]
/// <summary>"control"</summary>
Control,
[Mapping("dataarea")]
/// <summary>"dataarea"</summary>
DataArea,
[Mapping("device")]
/// <summary>"device"</summary>
Device,
[Mapping("device_ref", "deviceref")]
/// <summary>"device_ref", "deviceref"</summary>
DeviceRef,
[Mapping("diplocation")]
/// <summary>"diplocation"</summary>
DipLocation,
[Mapping("dipswitch")]
/// <summary>"dipswitch"</summary>
DipSwitch,
[Mapping("dipvalue")]
/// <summary>"dipvalue"</summary>
DipValue,
[Mapping("diskarea")]
/// <summary>"diskarea"</summary>
DiskArea,
[Mapping("display")]
/// <summary>"display"</summary>
Display,
[Mapping("driver")]
/// <summary>"driver"</summary>
Driver,
[Mapping("extension")]
/// <summary>"extension"</summary>
Extension,
[Mapping("feature")]
/// <summary>"feature"</summary>
Feature,
[Mapping("info")]
/// <summary>"info"</summary>
Info,
[Mapping("input")]
/// <summary>"input"</summary>
Input,
[Mapping("instance")]
/// <summary>"instance"</summary>
Instance,
[Mapping("original")]
/// <summary>"original"</summary>
Original,
[Mapping("part")]
/// <summary>"part"</summary>
Part,
[Mapping("part_feature", "partfeature")]
/// <summary>"part_feature", "partfeature"</summary>
PartFeature,
[Mapping("port")]
/// <summary>"port"</summary>
Port,
[Mapping("ramoption", "ram_option")]
/// <summary>"ramoption", "ram_option"</summary>
RamOption,
[Mapping("release")]
/// <summary>"release"</summary>
Release,
[Mapping("release_details", "releasedetails")]
/// <summary>"release_details", "releasedetails"</summary>
ReleaseDetails,
[Mapping("sample")]
/// <summary>"sample"</summary>
Sample,
[Mapping("serials")]
/// <summary>"serials"</summary>
Serials,
[Mapping("sharedfeat", "shared_feat", "sharedfeature", "shared_feature")]
/// <summary>"sharedfeat", "shared_feat", "sharedfeature", "shared_feature"</summary>
SharedFeat,
[Mapping("slot")]
/// <summary>"slot"</summary>
Slot,
[Mapping("slotoption", "slot_option")]
/// <summary>"slotoption", "slot_option"</summary>
SlotOption,
[Mapping("softwarelist", "software_list")]
/// <summary>"softwarelist", "software_list"</summary>
SoftwareList,
[Mapping("sound")]
/// <summary>"sound"</summary>
Sound,
[Mapping("source_details", "sourcedetails")]
/// <summary>"source_details", "sourcedetails"</summary>
SourceDetails,
[Mapping("blank")]
/// <summary>"blank"</summary>
Blank = 99, // This is not a real type, only used internally
}
/// <summary>
/// Determine the loadflag value
/// </summary>
[Flags]
public enum LoadFlag
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("load16_byte")]
Load16Byte = 1 << 0,
[Mapping("load16_word")]
Load16Word = 1 << 1,
[Mapping("load16_word_swap")]
Load16WordSwap = 1 << 2,
[Mapping("load32_byte")]
Load32Byte = 1 << 3,
[Mapping("load32_word")]
Load32Word = 1 << 4,
[Mapping("load32_word_swap")]
Load32WordSwap = 1 << 5,
[Mapping("load32_dword")]
Load32DWord = 1 << 6,
[Mapping("load64_word")]
Load64Word = 1 << 7,
[Mapping("load64_word_swap")]
Load64WordSwap = 1 << 8,
[Mapping("reload")]
Reload = 1 << 9,
[Mapping("fill")]
Fill = 1 << 10,
[Mapping("continue")]
Continue = 1 << 11,
[Mapping("reload_plain")]
ReloadPlain = 1 << 12,
[Mapping("ignore")]
Ignore = 1 << 13,
}
/// <summary>
/// Determine what type of machine it is
/// </summary>
[Flags]
public enum MachineType
{
[Mapping("none")]
/// <summary>"none"</summary>
None = 0,
[Mapping("bios")]
/// <summary>"bios"</summary>
Bios = 1 << 0,
[Mapping("device", "dev")]
/// <summary>"device", "dev"</summary>
Device = 1 << 1,
[Mapping("mechanical", "mech")]
/// <summary>"mechanical", "mech"</summary>
Mechanical = 1 << 2,
}
/// <summary>
/// Determine which OpenMSX subtype an item is
/// </summary>
[Flags]
public enum OpenMSXSubType
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("rom")]
Rom = 1 << 0,
[Mapping("megarom")]
MegaRom = 1 << 1,
[Mapping("sccpluscart")]
SCCPlusCart = 1 << 2,
}
/// <summary>
/// Determine relation of value to condition
/// </summary>
[Flags]
public enum Relation
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("eq")]
Equal = 1 << 0,
[Mapping("ne")]
NotEqual = 1 << 1,
[Mapping("gt")]
GreaterThan = 1 << 2,
[Mapping("le")]
LessThanOrEqual = 1 << 3,
[Mapping("lt")]
LessThan = 1 << 4,
[Mapping("ge")]
GreaterThanOrEqual = 1 << 5,
}
/// <summary>
/// Determine machine runnable status
/// </summary>
[Flags]
public enum Runnable
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("no")]
No = 1 << 0,
[Mapping("partial")]
Partial = 1 << 1,
[Mapping("yes")]
Yes = 1 << 2,
}
/// <summary>
/// Determine software list status
/// </summary>
[Flags]
public enum SoftwareListStatus
{
[Mapping("none")]
None = 0,
[Mapping("original")]
Original = 1 << 0,
[Mapping("compatible")]
Compatible = 1 << 1,
}
/// <summary>
/// Determine machine support status
/// </summary>
[Flags]
public enum Supported
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("no", "unsupported")]
No = 1 << 0,
[Mapping("partial")]
Partial = 1 << 1,
[Mapping("yes", "supported")]
Yes = 1 << 2,
}
/// <summary>
/// Determine driver support statuses
/// </summary>
[Flags]
public enum SupportStatus
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
[Mapping("good")]
Good = 1 << 0,
[Mapping("imperfect")]
Imperfect = 1 << 1,
[Mapping("preliminary")]
Preliminary = 1 << 2,
}
}

View File

@@ -1,345 +1,9 @@
using System.Collections.Generic;
namespace SabreTools.Metadata.DatItems
{
public static class Extensions
{
#region Private Maps
/// <summary>
/// Set of enum to string mappings for ChipType
/// </summary>
private static readonly Dictionary<string, ChipType> _toChipTypeMap = Converters.GenerateToEnum<ChipType>();
/// <summary>
/// Set of string to enum mappings for ChipType
/// </summary>
private static readonly Dictionary<ChipType, string> _fromChipTypeMap = Converters.GenerateToString<ChipType>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for ControlType
/// </summary>
private static readonly Dictionary<string, ControlType> _toControlTypeMap = Converters.GenerateToEnum<ControlType>();
/// <summary>
/// Set of string to enum mappings for ControlType
/// </summary>
private static readonly Dictionary<ControlType, string> _fromControlTypeMap = Converters.GenerateToString<ControlType>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for DeviceType
/// </summary>
private static readonly Dictionary<string, DeviceType> _toDeviceTypeMap = Converters.GenerateToEnum<DeviceType>();
/// <summary>
/// Set of string to enum mappings for DeviceType
/// </summary>
private static readonly Dictionary<DeviceType, string> _fromDeviceTypeMap = Converters.GenerateToString<DeviceType>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for DisplayType
/// </summary>
private static readonly Dictionary<string, DisplayType> _toDisplayTypeMap = Converters.GenerateToEnum<DisplayType>();
/// <summary>
/// Set of string to enum mappings for DisplayType
/// </summary>
private static readonly Dictionary<DisplayType, string> _fromDisplayTypeMap = Converters.GenerateToString<DisplayType>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for Endianness
/// </summary>
private static readonly Dictionary<string, Endianness> _toEndiannessMap = Converters.GenerateToEnum<Endianness>();
/// <summary>
/// Set of string to enum mappings for Endianness
/// </summary>
private static readonly Dictionary<Endianness, string> _fromEndiannessMap = Converters.GenerateToString<Endianness>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for FeatureStatus
/// </summary>
private static readonly Dictionary<string, FeatureStatus> _toFeatureStatusMap = Converters.GenerateToEnum<FeatureStatus>();
/// <summary>
/// Set of string to enum mappings for FeatureStatus
/// </summary>
private static readonly Dictionary<FeatureStatus, string> _fromFeatureStatusMap = Converters.GenerateToString<FeatureStatus>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for FeatureType
/// </summary>
private static readonly Dictionary<string, FeatureType> _toFeatureTypeMap = Converters.GenerateToEnum<FeatureType>();
/// <summary>
/// Set of string to enum mappings for FeatureType
/// </summary>
private static readonly Dictionary<FeatureType, string> _fromFeatureTypeMap = Converters.GenerateToString<FeatureType>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for ItemStatus
/// </summary>
private static readonly Dictionary<string, ItemStatus> _toItemStatusMap = Converters.GenerateToEnum<ItemStatus>();
/// <summary>
/// Set of string to enum mappings for ItemStatus
/// </summary>
private static readonly Dictionary<ItemStatus, string> _fromItemStatusMap = Converters.GenerateToString<ItemStatus>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for ItemType
/// </summary>
private static readonly Dictionary<string, ItemType> _toItemTypeMap = Converters.GenerateToEnum<ItemType>();
/// <summary>
/// Set of string to enum mappings for ItemType
/// </summary>
private static readonly Dictionary<ItemType, string> _fromItemTypeMap = Converters.GenerateToString<ItemType>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for LoadFlag
/// </summary>
private static readonly Dictionary<string, LoadFlag> _toLoadFlagMap = Converters.GenerateToEnum<LoadFlag>();
/// <summary>
/// Set of string to enum mappings for LoadFlag
/// </summary>
private static readonly Dictionary<LoadFlag, string> _fromLoadFlagMap = Converters.GenerateToString<LoadFlag>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for MachineType
/// </summary>
private static readonly Dictionary<string, MachineType> _toMachineTypeMap = Converters.GenerateToEnum<MachineType>();
/// <summary>
/// Set of enum to string mappings for OpenMSXSubType
/// </summary>
private static readonly Dictionary<string, OpenMSXSubType> _toOpenMSXSubTypeMap = Converters.GenerateToEnum<OpenMSXSubType>();
/// <summary>
/// Set of string to enum mappings for OpenMSXSubType
/// </summary>
private static readonly Dictionary<OpenMSXSubType, string> _fromOpenMSXSubTypeMap = Converters.GenerateToString<OpenMSXSubType>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for Relation
/// </summary>
private static readonly Dictionary<string, Relation> _toRelationMap = Converters.GenerateToEnum<Relation>();
/// <summary>
/// Set of string to enum mappings for Relation
/// </summary>
private static readonly Dictionary<Relation, string> _fromRelationMap = Converters.GenerateToString<Relation>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for Runnable
/// </summary>
private static readonly Dictionary<string, Runnable> _toRunnableMap = Converters.GenerateToEnum<Runnable>();
/// <summary>
/// Set of string to enum mappings for Runnable
/// </summary>
private static readonly Dictionary<Runnable, string> _fromRunnableMap = Converters.GenerateToString<Runnable>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for SoftwareListStatus
/// </summary>
private static readonly Dictionary<string, SoftwareListStatus> _toSoftwareListStatusMap = Converters.GenerateToEnum<SoftwareListStatus>();
/// <summary>
/// Set of string to enum mappings for SoftwareListStatus
/// </summary>
private static readonly Dictionary<SoftwareListStatus, string> _fromSoftwareListStatusMap = Converters.GenerateToString<SoftwareListStatus>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for Supported
/// </summary>
private static readonly Dictionary<string, Supported> _toSupportedMap = Converters.GenerateToEnum<Supported>();
/// <summary>
/// Set of string to enum mappings for Supported
/// </summary>
private static readonly Dictionary<Supported, string> _fromSupportedMap = Converters.GenerateToString<Supported>(useSecond: false);
/// <summary>
/// Set of string to enum mappings for Supported (secondary)
/// </summary>
private static readonly Dictionary<Supported, string> _fromSupportedSecondaryMap = Converters.GenerateToString<Supported>(useSecond: true);
/// <summary>
/// Set of enum to string mappings for SupportStatus
/// </summary>
private static readonly Dictionary<string, SupportStatus> _toSupportStatusMap = Converters.GenerateToEnum<SupportStatus>();
/// <summary>
/// Set of string to enum mappings for SupportStatus
/// </summary>
private static readonly Dictionary<SupportStatus, string> _fromSupportStatusMap = Converters.GenerateToString<SupportStatus>(useSecond: false);
#endregion
#region String to Enum
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static ChipType AsChipType(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toChipTypeMap.ContainsKey(value))
return _toChipTypeMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static ControlType AsControlType(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toControlTypeMap.ContainsKey(value))
return _toControlTypeMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static DeviceType AsDeviceType(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toDeviceTypeMap.ContainsKey(value))
return _toDeviceTypeMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static DisplayType AsDisplayType(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toDisplayTypeMap.ContainsKey(value))
return _toDisplayTypeMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static Endianness AsEndianness(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toEndiannessMap.ContainsKey(value))
return _toEndiannessMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static FeatureStatus AsFeatureStatus(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toFeatureStatusMap.ContainsKey(value))
return _toFeatureStatusMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static FeatureType AsFeatureType(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toFeatureTypeMap.ContainsKey(value))
return _toFeatureTypeMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static ItemStatus AsItemStatus(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toItemStatusMap.ContainsKey(value))
return _toItemStatusMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
@@ -347,37 +11,57 @@ namespace SabreTools.Metadata.DatItems
/// <returns>Enum value representing the input, default on error</returns>
public static ItemType AsItemType(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
return value?.ToLowerInvariant() switch
{
// "Actionable" item types
"rom" => ItemType.Rom,
"disk" => ItemType.Disk,
"file" => ItemType.File,
"media" => ItemType.Media,
// Try to get the value from the mappings
if (_toItemTypeMap.ContainsKey(value))
return _toItemTypeMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static LoadFlag AsLoadFlag(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toLoadFlagMap.ContainsKey(value))
return _toLoadFlagMap[value];
// Otherwise, return the default value for the enum
return default;
// "Auxiliary" item types
"adjuster" => ItemType.Adjuster,
"analog" => ItemType.Analog,
"archive" => ItemType.Archive,
"biosset" => ItemType.BiosSet,
"chip" => ItemType.Chip,
"condition" => ItemType.Condition,
"configuration" => ItemType.Configuration,
"conflocation" => ItemType.ConfLocation,
"confsetting" => ItemType.ConfSetting,
"control" => ItemType.Control,
"dataarea" => ItemType.DataArea,
"device" => ItemType.Device,
"device_ref" or "deviceref" => ItemType.DeviceRef,
"diplocation" => ItemType.DipLocation,
"dipswitch" => ItemType.DipSwitch,
"dipvalue" => ItemType.DipValue,
"diskarea" => ItemType.DiskArea,
"display" => ItemType.Display,
"driver" => ItemType.Driver,
"extension" => ItemType.Extension,
"feature" => ItemType.Feature,
"info" => ItemType.Info,
"input" => ItemType.Input,
"instance" => ItemType.Instance,
"original" => ItemType.Original,
"part" => ItemType.Part,
"part_feature" or "partfeature" => ItemType.PartFeature,
"port" => ItemType.Port,
"ramoption" or "ram_option" => ItemType.RamOption,
"release" => ItemType.Release,
"release_details" or "releasedetails" => ItemType.ReleaseDetails,
"sample" => ItemType.Sample,
"serials" => ItemType.Serials,
"sharedfeat" or "shared_feat" or "sharedfeature" or "shared_feature" => ItemType.SharedFeat,
"slot" => ItemType.Slot,
"slotoption" or "slot_option" => ItemType.SlotOption,
"softwarelist" or "software_list" => ItemType.SoftwareList,
"sound" => ItemType.Sound,
"source_details" or "sourcedetails" => ItemType.SourceDetails,
"blank" => ItemType.Blank,
_ => ItemType.NULL,
};
}
/// <summary>
@@ -387,137 +71,14 @@ namespace SabreTools.Metadata.DatItems
/// <returns>Enum value representing the input, default on error</returns>
public static MachineType AsMachineType(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toMachineTypeMap.ContainsKey(value))
return _toMachineTypeMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static OpenMSXSubType AsOpenMSXSubType(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toOpenMSXSubTypeMap.ContainsKey(value))
return _toOpenMSXSubTypeMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static Relation AsRelation(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toRelationMap.ContainsKey(value))
return _toRelationMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static Runnable AsRunnable(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toRunnableMap.ContainsKey(value))
return _toRunnableMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static SoftwareListStatus AsSoftwareListStatus(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toSoftwareListStatusMap.ContainsKey(value))
return _toSoftwareListStatusMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static Supported AsSupported(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toSupportedMap.ContainsKey(value))
return _toSupportedMap[value];
// Otherwise, return the default value for the enum
return default;
}
/// <summary>
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <returns>Enum value representing the input, default on error</returns>
public static SupportStatus AsSupportStatus(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value is null)
return default;
// Try to get the value from the mappings
if (_toSupportStatusMap.ContainsKey(value))
return _toSupportStatusMap[value];
// Otherwise, return the default value for the enum
return default;
return value?.ToLowerInvariant() switch
{
"none" => MachineType.None,
"bios" => MachineType.Bios,
"device" or "dev" => MachineType.Device,
"mechanical" or "mech" => MachineType.Mechanical,
_ => MachineType.None,
};
}
#endregion
@@ -528,258 +89,63 @@ namespace SabreTools.Metadata.DatItems
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this ChipType value)
{
// Try to get the value from the mappings
if (_fromChipTypeMap.ContainsKey(value))
return _fromChipTypeMap[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this ControlType value)
{
// Try to get the value from the mappings
if (_fromControlTypeMap.ContainsKey(value))
return _fromControlTypeMap[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this DeviceType value)
{
// Try to get the value from the mappings
if (_fromDeviceTypeMap.ContainsKey(value))
return _fromDeviceTypeMap[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this DisplayType value)
{
// Try to get the value from the mappings
if (_fromDisplayTypeMap.ContainsKey(value))
return _fromDisplayTypeMap[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this Endianness value)
{
// Try to get the value from the mappings
if (_fromEndiannessMap.ContainsKey(value))
return _fromEndiannessMap[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this FeatureStatus value)
{
// Try to get the value from the mappings
if (_fromFeatureStatusMap.ContainsKey(value))
return _fromFeatureStatusMap[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this FeatureType value)
{
// Try to get the value from the mappings
if (_fromFeatureTypeMap.ContainsKey(value))
return _fromFeatureTypeMap[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this ItemStatus value)
{
// Try to get the value from the mappings
if (_fromItemStatusMap.ContainsKey(value))
return _fromItemStatusMap[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this ItemType value)
{
// Try to get the value from the mappings
if (_fromItemTypeMap.ContainsKey(value))
return _fromItemTypeMap[value];
return value switch
{
// "Actionable" item types
ItemType.Rom => "rom",
ItemType.Disk => "disk",
ItemType.File => "file",
ItemType.Media => "media",
// Otherwise, return null
return null;
}
// "Auxiliary" item types
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this LoadFlag value)
{
// Try to get the value from the mappings
if (_fromLoadFlagMap.ContainsKey(value))
return _fromLoadFlagMap[value];
ItemType.Adjuster => "adjuster",
ItemType.Analog => "analog",
ItemType.Archive => "archive",
ItemType.BiosSet => "biosset",
ItemType.Chip => "chip",
ItemType.Condition => "condition",
ItemType.Configuration => "configuration",
ItemType.ConfLocation => "conflocation",
ItemType.ConfSetting => "confsetting",
ItemType.Control => "control",
ItemType.DataArea => "dataarea",
ItemType.Device => "device",
ItemType.DeviceRef => "device_ref",
ItemType.DipLocation => "diplocation",
ItemType.DipSwitch => "dipswitch",
ItemType.DipValue => "dipvalue",
ItemType.DiskArea => "diskarea",
ItemType.Display => "display",
ItemType.Driver => "driver",
ItemType.Extension => "extension",
ItemType.Feature => "feature",
ItemType.Info => "info",
ItemType.Input => "input",
ItemType.Instance => "instance",
ItemType.Original => "original",
ItemType.Part => "part",
ItemType.PartFeature => "part_feature",
ItemType.Port => "port",
ItemType.RamOption => "ramoption",
ItemType.Release => "release",
ItemType.ReleaseDetails => "release_details",
ItemType.Sample => "sample",
ItemType.Serials => "serials",
ItemType.SharedFeat => "sharedfeat",
ItemType.Slot => "slot",
ItemType.SlotOption => "slotoption",
ItemType.SoftwareList => "softwarelist",
ItemType.Sound => "sound",
ItemType.SourceDetails => "source_details",
ItemType.Blank => "blank",
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this OpenMSXSubType value)
{
// Try to get the value from the mappings
if (_fromOpenMSXSubTypeMap.ContainsKey(value))
return _fromOpenMSXSubTypeMap[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this Relation value)
{
// Try to get the value from the mappings
if (_fromRelationMap.ContainsKey(value))
return _fromRelationMap[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this Runnable value)
{
// Try to get the value from the mappings
if (_fromRunnableMap.ContainsKey(value))
return _fromRunnableMap[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this SoftwareListStatus value)
{
// Try to get the value from the mappings
if (_fromSoftwareListStatusMap.ContainsKey(value))
return _fromSoftwareListStatusMap[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this Supported value, bool useSecond = false)
{
// Try to get the value from the mappings
if (!useSecond && _fromSupportedMap.ContainsKey(value))
return _fromSupportedMap[value];
else if (useSecond && _fromSupportedSecondaryMap.ContainsKey(value))
return _fromSupportedSecondaryMap[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get the string value for an input enum, if possible
/// </summary>
/// <param name="value">Enum value to parse/param>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue(this SupportStatus value)
{
// Try to get the value from the mappings
if (_fromSupportStatusMap.ContainsKey(value))
return _fromSupportStatusMap[value];
// Otherwise, return null
return null;
ItemType.NULL => null,
_ => null,
};
}
#endregion

View File

@@ -1,5 +1,6 @@
using System.Xml.Serialization;
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Data.Extensions;
namespace SabreTools.Metadata.DatItems.Formats
{
@@ -29,7 +30,7 @@ namespace SabreTools.Metadata.DatItems.Formats
string? chipType = ReadString(Data.Models.Metadata.Chip.ChipTypeKey);
if (chipType is not null)
Write<string?>(Data.Models.Metadata.Chip.ChipTypeKey, chipType.AsChipType().AsStringValue());
Write<string?>(Data.Models.Metadata.Chip.ChipTypeKey, chipType.AsChipType()?.AsStringValue());
}
public Chip(Data.Models.Metadata.Chip item, Machine machine, Source source) : this(item)

View File

@@ -1,5 +1,6 @@
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Data.Extensions;
namespace SabreTools.Metadata.DatItems.Formats
{
@@ -25,7 +26,7 @@ namespace SabreTools.Metadata.DatItems.Formats
// Process flag values
string? condition = ReadString(Data.Models.Metadata.Condition.RelationKey);
if (condition is not null)
Write<string?>(Data.Models.Metadata.Condition.RelationKey, condition.AsRelation().AsStringValue());
Write<string?>(Data.Models.Metadata.Condition.RelationKey, condition.AsRelation()?.AsStringValue());
}
public Condition(Data.Models.Metadata.Condition item, Machine machine, Source source) : this(item)

View File

@@ -1,5 +1,6 @@
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Data.Extensions;
namespace SabreTools.Metadata.DatItems.Formats
{
@@ -57,7 +58,7 @@ namespace SabreTools.Metadata.DatItems.Formats
string? controlType = ReadString(Data.Models.Metadata.Control.ControlTypeKey);
if (controlType is not null)
Write<string?>(Data.Models.Metadata.Control.ControlTypeKey, controlType.AsControlType().AsStringValue());
Write<string?>(Data.Models.Metadata.Control.ControlTypeKey, controlType.AsControlType()?.AsStringValue());
}
public Control(Data.Models.Metadata.Control item, Machine machine, Source source) : this(item)

View File

@@ -1,5 +1,6 @@
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Data.Extensions;
namespace SabreTools.Metadata.DatItems.Formats
{
@@ -26,7 +27,7 @@ namespace SabreTools.Metadata.DatItems.Formats
// Process flag values
string? endianness = ReadString(Data.Models.Metadata.DataArea.EndiannessKey);
if (endianness is not null)
Write<string?>(Data.Models.Metadata.DataArea.EndiannessKey, endianness.AsEndianness().AsStringValue());
Write<string?>(Data.Models.Metadata.DataArea.EndiannessKey, endianness.AsEndianness()?.AsStringValue());
long? size = ReadLong(Data.Models.Metadata.DataArea.SizeKey);
if (size is not null)

View File

@@ -1,6 +1,7 @@
using System;
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Data.Extensions;
namespace SabreTools.Metadata.DatItems.Formats
{
@@ -50,7 +51,7 @@ namespace SabreTools.Metadata.DatItems.Formats
string? deviceType = ReadString(Data.Models.Metadata.Device.DeviceTypeKey);
if (deviceType is not null)
Write<string?>(Data.Models.Metadata.Device.DeviceTypeKey, deviceType.AsDeviceType().AsStringValue());
Write<string?>(Data.Models.Metadata.Device.DeviceTypeKey, deviceType.AsDeviceType()?.AsStringValue());
// Handle subitems
var instance = item.Read<Data.Models.Metadata.Instance>(Data.Models.Metadata.Device.InstanceKey);

View File

@@ -1,6 +1,7 @@
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Data.Extensions;
using SabreTools.Data.Models.Metadata;
using SabreTools.Text.Extensions;
namespace SabreTools.Metadata.DatItems.Formats
@@ -73,7 +74,7 @@ namespace SabreTools.Metadata.DatItems.Formats
string? status = ReadString(Data.Models.Metadata.Disk.StatusKey);
if (status is not null)
Write<string?>(Data.Models.Metadata.Disk.StatusKey, status.AsItemStatus().AsStringValue());
Write<string?>(Data.Models.Metadata.Disk.StatusKey, status.AsItemStatus()?.AsStringValue());
bool? writable = ReadBool(Data.Models.Metadata.Disk.WritableKey);
if (writable is not null)

View File

@@ -1,5 +1,6 @@
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Data.Extensions;
using SabreTools.Text.Extensions;
namespace SabreTools.Metadata.DatItems.Formats
@@ -58,7 +59,7 @@ namespace SabreTools.Metadata.DatItems.Formats
string? displayType = ReadString(Data.Models.Metadata.Display.DisplayTypeKey);
if (displayType is not null)
Write<string?>(Data.Models.Metadata.Display.DisplayTypeKey, displayType.AsDisplayType().AsStringValue());
Write<string?>(Data.Models.Metadata.Display.DisplayTypeKey, displayType.AsDisplayType()?.AsStringValue());
long? vbEnd = ReadLong(Data.Models.Metadata.Display.VBEndKey);
if (vbEnd is not null)
@@ -88,7 +89,7 @@ namespace SabreTools.Metadata.DatItems.Formats
// TODO: Convert this block to more traditional set of if/then
Write(Data.Models.Metadata.Video.AspectXKey, NumberHelper.ConvertToInt64(item.ReadString(Data.Models.Metadata.Video.AspectXKey)));
Write(Data.Models.Metadata.Video.AspectYKey, NumberHelper.ConvertToInt64(item.ReadString(Data.Models.Metadata.Video.AspectYKey)));
Write<string?>(Data.Models.Metadata.Display.DisplayTypeKey, item.ReadString(Data.Models.Metadata.Video.ScreenKey).AsDisplayType().AsStringValue());
Write<string?>(Data.Models.Metadata.Display.DisplayTypeKey, item.ReadString(Data.Models.Metadata.Video.ScreenKey).AsDisplayType()?.AsStringValue());
Write(Data.Models.Metadata.Display.HeightKey, NumberHelper.ConvertToInt64(item.ReadString(Data.Models.Metadata.Video.HeightKey)));
Write(Data.Models.Metadata.Display.RefreshKey, NumberHelper.ConvertToDouble(item.ReadString(Data.Models.Metadata.Video.RefreshKey)));
Write(Data.Models.Metadata.Display.WidthKey, NumberHelper.ConvertToInt64(item.ReadString(Data.Models.Metadata.Video.WidthKey)));
@@ -125,7 +126,7 @@ namespace SabreTools.Metadata.DatItems.Formats
string? screen = ReadString(Data.Models.Metadata.Video.ScreenKey);
if (screen is not null)
Write<string?>(Data.Models.Metadata.Display.DisplayTypeKey, screen.AsDisplayType().AsStringValue());
Write<string?>(Data.Models.Metadata.Display.DisplayTypeKey, screen.AsDisplayType()?.AsStringValue());
long? width = ReadLong(Data.Models.Metadata.Video.WidthKey);
if (width is not null)

View File

@@ -1,5 +1,6 @@
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Data.Extensions;
namespace SabreTools.Metadata.DatItems.Formats
{
@@ -25,15 +26,15 @@ namespace SabreTools.Metadata.DatItems.Formats
// Process flag values
string? cocktail = ReadString(Data.Models.Metadata.Driver.CocktailKey);
if (cocktail is not null)
Write<string?>(Data.Models.Metadata.Driver.CocktailKey, cocktail.AsSupportStatus().AsStringValue());
Write<string?>(Data.Models.Metadata.Driver.CocktailKey, cocktail.AsSupportStatus()?.AsStringValue());
string? color = ReadString(Data.Models.Metadata.Driver.ColorKey);
if (color is not null)
Write<string?>(Data.Models.Metadata.Driver.ColorKey, color.AsSupportStatus().AsStringValue());
Write<string?>(Data.Models.Metadata.Driver.ColorKey, color.AsSupportStatus()?.AsStringValue());
string? emulation = ReadString(Data.Models.Metadata.Driver.EmulationKey);
if (emulation is not null)
Write<string?>(Data.Models.Metadata.Driver.EmulationKey, emulation.AsSupportStatus().AsStringValue());
Write<string?>(Data.Models.Metadata.Driver.EmulationKey, emulation.AsSupportStatus()?.AsStringValue());
bool? incomplete = ReadBool(Data.Models.Metadata.Driver.IncompleteKey);
if (incomplete is not null)
@@ -53,15 +54,15 @@ namespace SabreTools.Metadata.DatItems.Formats
string? saveState = ReadString(Data.Models.Metadata.Driver.SaveStateKey);
if (saveState is not null)
Write<string?>(Data.Models.Metadata.Driver.SaveStateKey, saveState.AsSupported().AsStringValue(useSecond: true));
Write<string?>(Data.Models.Metadata.Driver.SaveStateKey, saveState.AsSupported()?.AsStringValue(useSecond: true));
string? sound = ReadString(Data.Models.Metadata.Driver.SoundKey);
if (sound is not null)
Write<string?>(Data.Models.Metadata.Driver.SoundKey, sound.AsSupportStatus().AsStringValue());
Write<string?>(Data.Models.Metadata.Driver.SoundKey, sound.AsSupportStatus()?.AsStringValue());
string? status = ReadString(Data.Models.Metadata.Driver.StatusKey);
if (status is not null)
Write<string?>(Data.Models.Metadata.Driver.StatusKey, status.AsSupportStatus().AsStringValue());
Write<string?>(Data.Models.Metadata.Driver.StatusKey, status.AsSupportStatus()?.AsStringValue());
bool? unofficial = ReadBool(Data.Models.Metadata.Driver.UnofficialKey);
if (unofficial is not null)

View File

@@ -1,5 +1,6 @@
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Data.Extensions;
namespace SabreTools.Metadata.DatItems.Formats
{
@@ -25,15 +26,15 @@ namespace SabreTools.Metadata.DatItems.Formats
// Process flag values
string? overall = ReadString(Data.Models.Metadata.Feature.OverallKey);
if (overall is not null)
Write<string?>(Data.Models.Metadata.Feature.OverallKey, overall.AsFeatureStatus().AsStringValue());
Write<string?>(Data.Models.Metadata.Feature.OverallKey, overall.AsFeatureStatus()?.AsStringValue());
string? status = ReadString(Data.Models.Metadata.Feature.StatusKey);
if (status is not null)
Write<string?>(Data.Models.Metadata.Feature.StatusKey, status.AsFeatureStatus().AsStringValue());
Write<string?>(Data.Models.Metadata.Feature.StatusKey, status.AsFeatureStatus()?.AsStringValue());
string? featureType = ReadString(Data.Models.Metadata.Feature.FeatureTypeKey);
if (featureType is not null)
Write<string?>(Data.Models.Metadata.Feature.FeatureTypeKey, featureType.AsFeatureType().AsStringValue());
Write<string?>(Data.Models.Metadata.Feature.FeatureTypeKey, featureType.AsFeatureType()?.AsStringValue());
}
public Feature(Data.Models.Metadata.Feature item, Machine machine, Source source) : this(item)

View File

@@ -1,5 +1,6 @@
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Data.Extensions;
namespace SabreTools.Metadata.DatItems.Formats
{
@@ -34,15 +35,15 @@ namespace SabreTools.Metadata.DatItems.Formats
// Process flag values
string? overall = ReadString(Data.Models.Metadata.Feature.OverallKey);
if (overall is not null)
Write<string?>(Data.Models.Metadata.Feature.OverallKey, overall.AsFeatureStatus().AsStringValue());
Write<string?>(Data.Models.Metadata.Feature.OverallKey, overall.AsFeatureStatus()?.AsStringValue());
string? status = ReadString(Data.Models.Metadata.Feature.StatusKey);
if (status is not null)
Write<string?>(Data.Models.Metadata.Feature.StatusKey, status.AsFeatureStatus().AsStringValue());
Write<string?>(Data.Models.Metadata.Feature.StatusKey, status.AsFeatureStatus()?.AsStringValue());
string? featureType = ReadString(Data.Models.Metadata.Feature.FeatureTypeKey);
if (featureType is not null)
Write<string?>(Data.Models.Metadata.Feature.FeatureTypeKey, featureType.AsFeatureType().AsStringValue());
Write<string?>(Data.Models.Metadata.Feature.FeatureTypeKey, featureType.AsFeatureType()?.AsStringValue());
}
public PartFeature(Data.Models.Metadata.Feature item, Machine machine, Source source) : this(item)

View File

@@ -1,6 +1,7 @@
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Data.Extensions;
using SabreTools.Data.Models.Metadata;
using SabreTools.Text.Extensions;
namespace SabreTools.Metadata.DatItems.Formats
@@ -36,7 +37,7 @@ namespace SabreTools.Metadata.DatItems.Formats
get
{
var status = ReadString(Data.Models.Metadata.Rom.StatusKey).AsItemStatus();
return status != ItemStatus.NULL && status != ItemStatus.None;
return status is not null && status != ItemStatus.None;
}
}
@@ -60,7 +61,7 @@ namespace SabreTools.Metadata.DatItems.Formats
&& (!string.IsNullOrEmpty(dataArea.GetName())
|| dataArea.ReadLong(Data.Models.Metadata.DataArea.SizeKey) is not null
|| dataArea.ReadLong(Data.Models.Metadata.DataArea.WidthKey) is not null
|| dataArea.ReadString(Data.Models.Metadata.DataArea.EndiannessKey).AsEndianness() != Endianness.NULL);
|| dataArea.ReadString(Data.Models.Metadata.DataArea.EndiannessKey).AsEndianness() is not null);
}
}
@@ -86,25 +87,25 @@ namespace SabreTools.Metadata.DatItems.Formats
Write<string?>(Data.Models.Metadata.Rom.StatusKey, ItemStatus.None.AsStringValue());
}
public Rom(Data.Models.Metadata.Dump item, Machine machine, Source source, int index)
public Rom(Dump item, Machine machine, Source source, int index)
{
// If we don't have rom data, we can't do anything
Data.Models.Metadata.Rom? rom = null;
OpenMSXSubType subType = OpenMSXSubType.NULL;
OpenMSXSubType? subType = null;
if (item.Read<Data.Models.Metadata.Rom>(Data.Models.Metadata.Dump.RomKey) is not null)
if (item.Read<Data.Models.Metadata.Rom>(Dump.RomKey) is not null)
{
rom = item.Read<Data.Models.Metadata.Rom>(Data.Models.Metadata.Dump.RomKey);
rom = item.Read<Data.Models.Metadata.Rom>(Dump.RomKey);
subType = OpenMSXSubType.Rom;
}
else if (item.Read<Data.Models.Metadata.Rom>(Data.Models.Metadata.Dump.MegaRomKey) is not null)
else if (item.Read<Data.Models.Metadata.Rom>(Dump.MegaRomKey) is not null)
{
rom = item.Read<Data.Models.Metadata.Rom>(Data.Models.Metadata.Dump.MegaRomKey);
rom = item.Read<Data.Models.Metadata.Rom>(Dump.MegaRomKey);
subType = OpenMSXSubType.MegaRom;
}
else if (item.Read<Data.Models.Metadata.Rom>(Data.Models.Metadata.Dump.SCCPlusCartKey) is not null)
else if (item.Read<Data.Models.Metadata.Rom>(Dump.SCCPlusCartKey) is not null)
{
rom = item.Read<Data.Models.Metadata.Rom>(Data.Models.Metadata.Dump.SCCPlusCartKey);
rom = item.Read<Data.Models.Metadata.Rom>(Dump.SCCPlusCartKey);
subType = OpenMSXSubType.SCCPlusCart;
}
@@ -116,14 +117,14 @@ namespace SabreTools.Metadata.DatItems.Formats
SetName(name);
Write<string?>(Data.Models.Metadata.Rom.OffsetKey, rom.ReadString(Data.Models.Metadata.Rom.StartKey));
Write<string?>(Data.Models.Metadata.Rom.OpenMSXMediaType, subType.AsStringValue());
Write<string?>(Data.Models.Metadata.Rom.OpenMSXMediaType, subType?.AsStringValue());
Write<string?>(Data.Models.Metadata.Rom.OpenMSXType, rom.ReadString(Data.Models.Metadata.Rom.OpenMSXType) ?? rom.ReadString(Data.Models.Metadata.DatItem.TypeKey));
Write<string?>(Data.Models.Metadata.Rom.RemarkKey, rom.ReadString(Data.Models.Metadata.Rom.RemarkKey));
Write<string?>(Data.Models.Metadata.Rom.SHA1Key, rom.ReadString(Data.Models.Metadata.Rom.SHA1Key));
Write<string?>(Data.Models.Metadata.Rom.StartKey, rom.ReadString(Data.Models.Metadata.Rom.StartKey));
Write<Source?>(SourceKey, source);
var original = item.Read<Data.Models.Metadata.Original>(Data.Models.Metadata.Dump.OriginalKey);
var original = item.Read<Data.Models.Metadata.Original>(Dump.OriginalKey);
if (original is not null)
{
Write<Original?>("ORIGINAL", new Original
@@ -206,11 +207,11 @@ namespace SabreTools.Metadata.DatItems.Formats
string? loadFlag = ReadString(Data.Models.Metadata.Rom.LoadFlagKey);
if (loadFlag is not null)
Write<string?>(Data.Models.Metadata.Rom.LoadFlagKey, loadFlag.AsLoadFlag().AsStringValue());
Write<string?>(Data.Models.Metadata.Rom.LoadFlagKey, loadFlag.AsLoadFlag()?.AsStringValue());
string? openMSXMediaType = ReadString(Data.Models.Metadata.Rom.OpenMSXMediaType);
if (openMSXMediaType is not null)
Write<string?>(Data.Models.Metadata.Rom.OpenMSXMediaType, openMSXMediaType.AsOpenMSXSubType().AsStringValue());
Write<string?>(Data.Models.Metadata.Rom.OpenMSXMediaType, openMSXMediaType.AsOpenMSXSubType()?.AsStringValue());
bool? mia = ReadBool(Data.Models.Metadata.Rom.MIAKey);
if (mia is not null)
@@ -226,7 +227,7 @@ namespace SabreTools.Metadata.DatItems.Formats
string? status = ReadString(Data.Models.Metadata.Rom.StatusKey);
if (status is not null)
Write<string?>(Data.Models.Metadata.Rom.StatusKey, status.AsItemStatus().AsStringValue());
Write<string?>(Data.Models.Metadata.Rom.StatusKey, status.AsItemStatus()?.AsStringValue());
// Process hash values
long? size = ReadLong(Data.Models.Metadata.Rom.SizeKey);

View File

@@ -1,5 +1,6 @@
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Data.Extensions;
namespace SabreTools.Metadata.DatItems.Formats
{
@@ -25,7 +26,7 @@ namespace SabreTools.Metadata.DatItems.Formats
// Process flag values
string? status = ReadString(Data.Models.Metadata.SoftwareList.StatusKey);
if (status is not null)
Write<string?>(Data.Models.Metadata.SoftwareList.StatusKey, status.AsSoftwareListStatus().AsStringValue());
Write<string?>(Data.Models.Metadata.SoftwareList.StatusKey, status.AsSoftwareListStatus()?.AsStringValue());
// Handle subitems
// TODO: Handle the Software subitem

View File

@@ -58,7 +58,7 @@ namespace SabreTools.Metadata.DatItems
string? supported = ReadString(Data.Models.Metadata.Machine.SupportedKey);
if (supported is not null)
Write<string?>(Data.Models.Metadata.Machine.SupportedKey, supported.AsSupported().AsStringValue());
Write<string?>(Data.Models.Metadata.Machine.SupportedKey, supported.AsSupported()?.AsStringValue());
// Handle Trurip object, if it exists
var truripItem = machine.Read<Data.Models.Logiqx.Trurip>(Data.Models.Metadata.Machine.TruripKey);