Replace AsStringValue for performance

This commit is contained in:
Matt Nadareski
2025-05-11 23:36:48 -04:00
parent bd09810180
commit b2c4f29264
8 changed files with 1159 additions and 774 deletions

View File

@@ -1,10 +1,8 @@
using SabreTools.Core.Tools;
using SabreTools.DatFiles;
using Xunit;
namespace SabreTools.Core.Test.Tools
{
// TODO: Remove reliance on anything but SabreTools.Core
public class ConvertersTests
{
#region String to Enum
@@ -26,57 +24,6 @@ namespace SabreTools.Core.Test.Tools
#region Enum to String
[Theory]
[InlineData(MergingFlag.None, true, "none")]
[InlineData(MergingFlag.None, false, "none")]
[InlineData(MergingFlag.Split, true, "split")]
[InlineData(MergingFlag.Split, false, "split")]
[InlineData(MergingFlag.Merged, true, "merged")]
[InlineData(MergingFlag.Merged, false, "merged")]
[InlineData(MergingFlag.NonMerged, true, "unmerged")]
[InlineData(MergingFlag.NonMerged, false, "nonmerged")]
[InlineData(MergingFlag.FullMerged, true, "fullmerged")]
[InlineData(MergingFlag.FullMerged, false, "fullmerged")]
[InlineData(MergingFlag.DeviceNonMerged, true, "deviceunmerged")]
[InlineData(MergingFlag.DeviceNonMerged, false, "device")]
[InlineData(MergingFlag.FullNonMerged, true, "fullunmerged")]
[InlineData(MergingFlag.FullNonMerged, false, "full")]
public void FromMergingFlagTest(MergingFlag field, bool useSecond, string? expected)
{
string? actual = field.AsStringValue<MergingFlag>(useSecond);
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(NodumpFlag.None, "none")]
[InlineData(NodumpFlag.Obsolete, "obsolete")]
[InlineData(NodumpFlag.Required, "required")]
[InlineData(NodumpFlag.Ignore, "ignore")]
public void FromNodumpFlagTest(NodumpFlag field, string? expected)
{
string? actual = field.AsStringValue<NodumpFlag>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(PackingFlag.None, true, "none")]
[InlineData(PackingFlag.None, false, "none")]
[InlineData(PackingFlag.Zip, true, "yes")]
[InlineData(PackingFlag.Zip, false, "zip")]
[InlineData(PackingFlag.Unzip, true, "no")]
[InlineData(PackingFlag.Unzip, false, "unzip")]
[InlineData(PackingFlag.Partial, true, "partial")]
[InlineData(PackingFlag.Partial, false, "partial")]
[InlineData(PackingFlag.Flat, true, "flat")]
[InlineData(PackingFlag.Flat, false, "flat")]
[InlineData(PackingFlag.FileOnly, true, "fileonly")]
[InlineData(PackingFlag.FileOnly, false, "fileonly")]
public void FromPackingFlagTest(PackingFlag field, bool useSecond, string? expected)
{
string? actual = field.AsStringValue<PackingFlag>(useSecond);
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, null)]
[InlineData(true, "yes")]
@@ -88,20 +35,5 @@ namespace SabreTools.Core.Test.Tools
}
#endregion
#region Generators
[Theory]
[InlineData(MergingFlag.None, 12)]
[InlineData(NodumpFlag.None, 4)]
[InlineData(PackingFlag.None, 8)]
public void GenerateToEnumTest<T>(T value, int expected)
{
var actual = Converters.GenerateToEnum<T>();
Assert.Equal(default, value);
Assert.Equal(expected, actual.Keys.Count);
}
#endregion
}
}

View File

@@ -27,7 +27,7 @@ namespace SabreTools.Core.Tools
/// </summary>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Dictionary of string to enum values</returns>
public static Dictionary<string, T> GenerateToEnum<T>() where T : notnull
public static Dictionary<string, T> GenerateToEnum<T>()
{
try
{
@@ -84,33 +84,13 @@ namespace SabreTools.Core.Tools
};
}
/// <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>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>String value representing the input, default on error</returns>
public static string? AsStringValue<T>(this T value, bool useSecond = false) where T : notnull
{
// Get the mapping dictionary
var mappings = GenerateToString<T>(useSecond);
// Try to get the value from the mappings
if (mappings.ContainsKey(value))
return mappings[value];
// Otherwise, return null
return null;
}
/// <summary>
/// Get a set of mappings from enum values to string
/// </summary>
/// <param name="useSecond">True to use the second mapping option, if it exists</param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Dictionary of enum to string values</returns>
internal static Dictionary<T, string> GenerateToString<T>(bool useSecond) where T : notnull
public static Dictionary<T, string> GenerateToString<T>(bool useSecond) where T : notnull
{
try
{

View File

@@ -0,0 +1,23 @@
using SabreTools.Core.Tools;
using Xunit;
namespace SabreTools.DatFiles.Test
{
public class ConvertersTests
{
#region Generators
[Theory]
[InlineData(MergingFlag.None, 12)]
[InlineData(NodumpFlag.None, 4)]
[InlineData(PackingFlag.None, 8)]
public void GenerateToEnumTest<T>(T value, int expected)
{
var actual = Converters.GenerateToEnum<T>();
Assert.Equal(default, value);
Assert.Equal(expected, actual.Keys.Count);
}
#endregion
}
}

View File

@@ -55,5 +55,60 @@ namespace SabreTools.DatFiles.Test
}
#endregion
#region Enum to String
[Theory]
[InlineData(MergingFlag.None, true, "none")]
[InlineData(MergingFlag.None, false, "none")]
[InlineData(MergingFlag.Split, true, "split")]
[InlineData(MergingFlag.Split, false, "split")]
[InlineData(MergingFlag.Merged, true, "merged")]
[InlineData(MergingFlag.Merged, false, "merged")]
[InlineData(MergingFlag.NonMerged, true, "unmerged")]
[InlineData(MergingFlag.NonMerged, false, "nonmerged")]
[InlineData(MergingFlag.FullMerged, true, "fullmerged")]
[InlineData(MergingFlag.FullMerged, false, "fullmerged")]
[InlineData(MergingFlag.DeviceNonMerged, true, "deviceunmerged")]
[InlineData(MergingFlag.DeviceNonMerged, false, "device")]
[InlineData(MergingFlag.FullNonMerged, true, "fullunmerged")]
[InlineData(MergingFlag.FullNonMerged, false, "full")]
public void FromMergingFlagTest(MergingFlag field, bool useSecond, string? expected)
{
string? actual = field.AsStringValue(useSecond);
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(NodumpFlag.None, "none")]
[InlineData(NodumpFlag.Obsolete, "obsolete")]
[InlineData(NodumpFlag.Required, "required")]
[InlineData(NodumpFlag.Ignore, "ignore")]
public void FromNodumpFlagTest(NodumpFlag field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(PackingFlag.None, true, "none")]
[InlineData(PackingFlag.None, false, "none")]
[InlineData(PackingFlag.Zip, true, "yes")]
[InlineData(PackingFlag.Zip, false, "zip")]
[InlineData(PackingFlag.Unzip, true, "no")]
[InlineData(PackingFlag.Unzip, false, "unzip")]
[InlineData(PackingFlag.Partial, true, "partial")]
[InlineData(PackingFlag.Partial, false, "partial")]
[InlineData(PackingFlag.Flat, true, "flat")]
[InlineData(PackingFlag.Flat, false, "flat")]
[InlineData(PackingFlag.FileOnly, true, "fileonly")]
[InlineData(PackingFlag.FileOnly, false, "fileonly")]
public void FromPackingFlagTest(PackingFlag field, bool useSecond, string? expected)
{
string? actual = field.AsStringValue(useSecond);
Assert.Equal(expected, actual);
}
#endregion
}
}

View File

@@ -10,17 +10,42 @@ namespace SabreTools.DatFiles
/// <summary>
/// Set of enum to string mappings for MergingFlag
/// </summary>
private static readonly Dictionary<string, MergingFlag> _mergingFlagMap = Converters.GenerateToEnum<MergingFlag>();
private static readonly Dictionary<string, MergingFlag> _toMergingFlagMap = Converters.GenerateToEnum<MergingFlag>();
/// <summary>
/// Set of string to enum mappings for MergingFlag
/// </summary>
private static readonly Dictionary<MergingFlag, string> _fromMergingFlagMap = Converters.GenerateToString<MergingFlag>(useSecond: false);
/// <summary>
/// Set of string to enum mappings for MergingFlag (secondary)
/// </summary>
private static readonly Dictionary<MergingFlag, string> _fromMergingFlagSecondaryMap = Converters.GenerateToString<MergingFlag>(useSecond: true);
/// <summary>
/// Set of enum to string mappings for NodumpFlag
/// </summary>
private static readonly Dictionary<string, NodumpFlag> _nodumpFlagMap = Converters.GenerateToEnum<NodumpFlag>();
private static readonly Dictionary<string, NodumpFlag> _toNodumpFlagMap = Converters.GenerateToEnum<NodumpFlag>();
/// <summary>
/// Set of string to enum mappings for NodumpFlag
/// </summary>
private static readonly Dictionary<NodumpFlag, string> _fromNodumpFlagMap = Converters.GenerateToString<NodumpFlag>(useSecond: false);
/// <summary>
/// Set of enum to string mappings for PackingFlag
/// </summary>
private static readonly Dictionary<string, PackingFlag> _packingFlagMap = Converters.GenerateToEnum<PackingFlag>();
private static readonly Dictionary<string, PackingFlag> _toPackingFlagMap = Converters.GenerateToEnum<PackingFlag>();
/// <summary>
/// Set of string to enum mappings for PackingFlag
/// </summary>
private static readonly Dictionary<PackingFlag, string> _fromPackingFlagMap = Converters.GenerateToString<PackingFlag>(useSecond: false);
/// <summary>
/// Set of string to enum mappings for PackingFlag (secondary)
/// </summary>
private static readonly Dictionary<PackingFlag, string> _fromPackingFlagSecondaryMap = Converters.GenerateToString<PackingFlag>(useSecond: true);
#endregion
@@ -30,7 +55,6 @@ namespace SabreTools.DatFiles
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static MergingFlag AsMergingFlag(this string? value)
{
@@ -40,8 +64,8 @@ namespace SabreTools.DatFiles
return default;
// Try to get the value from the mappings
if (_mergingFlagMap.ContainsKey(value))
return _mergingFlagMap[value];
if (_toMergingFlagMap.ContainsKey(value))
return _toMergingFlagMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -51,7 +75,6 @@ namespace SabreTools.DatFiles
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static NodumpFlag AsNodumpFlag(this string? value)
{
@@ -61,8 +84,8 @@ namespace SabreTools.DatFiles
return default;
// Try to get the value from the mappings
if (_nodumpFlagMap.ContainsKey(value))
return _nodumpFlagMap[value];
if (_toNodumpFlagMap.ContainsKey(value))
return _toNodumpFlagMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -72,7 +95,6 @@ namespace SabreTools.DatFiles
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static PackingFlag AsPackingFlag(this string? value)
{
@@ -82,13 +104,69 @@ namespace SabreTools.DatFiles
return default;
// Try to get the value from the mappings
if (_packingFlagMap.ContainsKey(value))
return _packingFlagMap[value];
if (_toPackingFlagMap.ContainsKey(value))
return _toPackingFlagMap[value];
// Otherwise, return the default value for the enum
return default;
}
#endregion
#region Enum to String
/// <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 MergingFlag value, bool useSecond = false)
{
// Try to get the value from the mappings
if (!useSecond && _fromMergingFlagMap.ContainsKey(value))
return _fromMergingFlagMap[value];
else if (useSecond && _fromMergingFlagSecondaryMap.ContainsKey(value))
return _fromMergingFlagSecondaryMap[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 NodumpFlag value)
{
// Try to get the value from the mappings
if (_fromNodumpFlagMap.ContainsKey(value))
return _fromNodumpFlagMap[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 PackingFlag value, bool useSecond = false)
{
// Try to get the value from the mappings
if (!useSecond && _fromPackingFlagMap.ContainsKey(value))
return _fromPackingFlagMap[value];
else if (useSecond && _fromPackingFlagSecondaryMap.ContainsKey(value))
return _fromPackingFlagSecondaryMap[value];
// Otherwise, return null
return null;
}
#endregion
}
}

View File

@@ -5,610 +5,6 @@ namespace SabreTools.DatItems.Test
{
public class ConvertersTests
{
#region String to Enum
[Theory]
[InlineData(null, ChipType.NULL)]
[InlineData("cpu", ChipType.CPU)]
[InlineData("audio", ChipType.Audio)]
public void AsChipTypeTest(string? field, ChipType expected)
{
ChipType actual = field.AsChipType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, ControlType.NULL)]
[InlineData("joy", ControlType.Joy)]
[InlineData("stick", ControlType.Stick)]
[InlineData("paddle", ControlType.Paddle)]
[InlineData("pedal", ControlType.Pedal)]
[InlineData("lightgun", ControlType.Lightgun)]
[InlineData("positional", ControlType.Positional)]
[InlineData("dial", ControlType.Dial)]
[InlineData("trackball", ControlType.Trackball)]
[InlineData("mouse", ControlType.Mouse)]
[InlineData("only_buttons", ControlType.OnlyButtons)]
[InlineData("keypad", ControlType.Keypad)]
[InlineData("keyboard", ControlType.Keyboard)]
[InlineData("mahjong", ControlType.Mahjong)]
[InlineData("hanafuda", ControlType.Hanafuda)]
[InlineData("gambling", ControlType.Gambling)]
public void AsControlTypeTest(string? field, ControlType expected)
{
ControlType actual = field.AsControlType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, DeviceType.NULL)]
[InlineData("unknown", DeviceType.Unknown)]
[InlineData("cartridge", DeviceType.Cartridge)]
[InlineData("floppydisk", DeviceType.FloppyDisk)]
[InlineData("harddisk", DeviceType.HardDisk)]
[InlineData("cylinder", DeviceType.Cylinder)]
[InlineData("cassette", DeviceType.Cassette)]
[InlineData("punchcard", DeviceType.PunchCard)]
[InlineData("punchtape", DeviceType.PunchTape)]
[InlineData("printout", DeviceType.Printout)]
[InlineData("serial", DeviceType.Serial)]
[InlineData("parallel", DeviceType.Parallel)]
[InlineData("snapshot", DeviceType.Snapshot)]
[InlineData("quickload", DeviceType.QuickLoad)]
[InlineData("memcard", DeviceType.MemCard)]
[InlineData("cdrom", DeviceType.CDROM)]
[InlineData("magtape", DeviceType.MagTape)]
[InlineData("romimage", DeviceType.ROMImage)]
[InlineData("midiin", DeviceType.MIDIIn)]
[InlineData("midiout", DeviceType.MIDIOut)]
[InlineData("picture", DeviceType.Picture)]
[InlineData("vidfile", DeviceType.VidFile)]
public void AsDeviceTypeTest(string? field, DeviceType expected)
{
DeviceType actual = field.AsDeviceType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, DisplayType.NULL)]
[InlineData("raster", DisplayType.Raster)]
[InlineData("vector", DisplayType.Vector)]
[InlineData("lcd", DisplayType.LCD)]
[InlineData("svg", DisplayType.SVG)]
[InlineData("unknown", DisplayType.Unknown)]
public void AsDisplayTypeTest(string? field, DisplayType expected)
{
DisplayType actual = field.AsDisplayType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, Endianness.NULL)]
[InlineData("big", Endianness.Big)]
[InlineData("little", Endianness.Little)]
public void AsEndiannessTest(string? field, Endianness expected)
{
Endianness actual = field.AsEndianness();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, FeatureStatus.NULL)]
[InlineData("unemulated", FeatureStatus.Unemulated)]
[InlineData("imperfect", FeatureStatus.Imperfect)]
public void AsFeatureStatusTest(string? field, FeatureStatus expected)
{
FeatureStatus actual = field.AsFeatureStatus();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, FeatureType.NULL)]
[InlineData("protection", FeatureType.Protection)]
[InlineData("palette", FeatureType.Palette)]
[InlineData("graphics", FeatureType.Graphics)]
[InlineData("sound", FeatureType.Sound)]
[InlineData("controls", FeatureType.Controls)]
[InlineData("keyboard", FeatureType.Keyboard)]
[InlineData("mouse", FeatureType.Mouse)]
[InlineData("microphone", FeatureType.Microphone)]
[InlineData("camera", FeatureType.Camera)]
[InlineData("disk", FeatureType.Disk)]
[InlineData("printer", FeatureType.Printer)]
[InlineData("lan", FeatureType.Lan)]
[InlineData("wan", FeatureType.Wan)]
[InlineData("timing", FeatureType.Timing)]
public void AsFeatureTypeTest(string? field, FeatureType expected)
{
FeatureType actual = field.AsFeatureType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, ItemStatus.NULL)]
[InlineData("none", ItemStatus.None)]
[InlineData("no", ItemStatus.None)]
[InlineData("good", ItemStatus.Good)]
[InlineData("baddump", ItemStatus.BadDump)]
[InlineData("nodump", ItemStatus.Nodump)]
[InlineData("yes", ItemStatus.Nodump)]
[InlineData("verified", ItemStatus.Verified)]
public void AsItemStatusTest(string? field, ItemStatus expected)
{
ItemStatus actual = field.AsItemStatus();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, ItemType.NULL)]
[InlineData("adjuster", ItemType.Adjuster)]
[InlineData("analog", ItemType.Analog)]
[InlineData("archive", ItemType.Archive)]
[InlineData("biosset", ItemType.BiosSet)]
[InlineData("blank", ItemType.Blank)]
[InlineData("chip", ItemType.Chip)]
[InlineData("condition", ItemType.Condition)]
[InlineData("configuration", ItemType.Configuration)]
[InlineData("conflocation", ItemType.ConfLocation)]
[InlineData("confsetting", ItemType.ConfSetting)]
[InlineData("control", ItemType.Control)]
[InlineData("dataarea", ItemType.DataArea)]
[InlineData("device", ItemType.Device)]
[InlineData("deviceref", ItemType.DeviceRef)]
[InlineData("device_ref", ItemType.DeviceRef)]
[InlineData("diplocation", ItemType.DipLocation)]
[InlineData("dipswitch", ItemType.DipSwitch)]
[InlineData("dipvalue", ItemType.DipValue)]
[InlineData("disk", ItemType.Disk)]
[InlineData("diskarea", ItemType.DiskArea)]
[InlineData("display", ItemType.Display)]
[InlineData("driver", ItemType.Driver)]
[InlineData("extension", ItemType.Extension)]
[InlineData("feature", ItemType.Feature)]
[InlineData("file", ItemType.File)]
[InlineData("info", ItemType.Info)]
[InlineData("input", ItemType.Input)]
[InlineData("instance", ItemType.Instance)]
[InlineData("media", ItemType.Media)]
[InlineData("part", ItemType.Part)]
[InlineData("partfeature", ItemType.PartFeature)]
[InlineData("part_feature", ItemType.PartFeature)]
[InlineData("port", ItemType.Port)]
[InlineData("ramoption", ItemType.RamOption)]
[InlineData("ram_option", ItemType.RamOption)]
[InlineData("release", ItemType.Release)]
[InlineData("releasedetails", ItemType.ReleaseDetails)]
[InlineData("release_details", ItemType.ReleaseDetails)]
[InlineData("rom", ItemType.Rom)]
[InlineData("sample", ItemType.Sample)]
[InlineData("serials", ItemType.Serials)]
[InlineData("sharedfeat", ItemType.SharedFeat)]
[InlineData("shared_feat", ItemType.SharedFeat)]
[InlineData("sharedfeature", ItemType.SharedFeat)]
[InlineData("shared_feature", ItemType.SharedFeat)]
[InlineData("slot", ItemType.Slot)]
[InlineData("slotoption", ItemType.SlotOption)]
[InlineData("slot_option", ItemType.SlotOption)]
[InlineData("softwarelist", ItemType.SoftwareList)]
[InlineData("software_list", ItemType.SoftwareList)]
[InlineData("sound", ItemType.Sound)]
[InlineData("sourcedetails", ItemType.SourceDetails)]
[InlineData("source_details", ItemType.SourceDetails)]
public void AsItemTypeTest(string? field, ItemType expected)
{
ItemType actual = field.AsItemType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, LoadFlag.NULL)]
[InlineData("load16_byte", LoadFlag.Load16Byte)]
[InlineData("load16_word", LoadFlag.Load16Word)]
[InlineData("load16_word_swap", LoadFlag.Load16WordSwap)]
[InlineData("load32_byte", LoadFlag.Load32Byte)]
[InlineData("load32_word", LoadFlag.Load32Word)]
[InlineData("load32_word_swap", LoadFlag.Load32WordSwap)]
[InlineData("load32_dword", LoadFlag.Load32DWord)]
[InlineData("load64_word", LoadFlag.Load64Word)]
[InlineData("load64_word_swap", LoadFlag.Load64WordSwap)]
[InlineData("reload", LoadFlag.Reload)]
[InlineData("fill", LoadFlag.Fill)]
[InlineData("continue", LoadFlag.Continue)]
[InlineData("reload_plain", LoadFlag.ReloadPlain)]
[InlineData("ignore", LoadFlag.Ignore)]
public void AsLoadFlagTest(string? field, LoadFlag expected)
{
LoadFlag actual = field.AsLoadFlag();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, MachineType.None)]
[InlineData("none", MachineType.None)]
[InlineData("bios", MachineType.Bios)]
[InlineData("dev", MachineType.Device)]
[InlineData("device", MachineType.Device)]
[InlineData("mech", MachineType.Mechanical)]
[InlineData("mechanical", MachineType.Mechanical)]
public void AsMachineTypeTest(string? field, MachineType expected)
{
MachineType actual = field.AsMachineType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, OpenMSXSubType.NULL)]
[InlineData("rom", OpenMSXSubType.Rom)]
[InlineData("megarom", OpenMSXSubType.MegaRom)]
[InlineData("sccpluscart", OpenMSXSubType.SCCPlusCart)]
public void AsOpenMSXSubTypeTest(string? field, OpenMSXSubType expected)
{
OpenMSXSubType actual = field.AsOpenMSXSubType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, Relation.NULL)]
[InlineData("eq", Relation.Equal)]
[InlineData("ne", Relation.NotEqual)]
[InlineData("gt", Relation.GreaterThan)]
[InlineData("le", Relation.LessThanOrEqual)]
[InlineData("lt", Relation.LessThan)]
[InlineData("ge", Relation.GreaterThanOrEqual)]
public void AsRelationTest(string? field, Relation expected)
{
Relation actual = field.AsRelation();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, Runnable.NULL)]
[InlineData("no", Runnable.No)]
[InlineData("partial", Runnable.Partial)]
[InlineData("yes", Runnable.Yes)]
public void AsRunnableTest(string? field, Runnable expected)
{
Runnable actual = field.AsRunnable();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, SoftwareListStatus.None)]
[InlineData("none", SoftwareListStatus.None)]
[InlineData("original", SoftwareListStatus.Original)]
[InlineData("compatible", SoftwareListStatus.Compatible)]
public void AsSoftwareListStatusTest(string? field, SoftwareListStatus expected)
{
SoftwareListStatus actual = field.AsSoftwareListStatus();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, Supported.NULL)]
[InlineData("no", Supported.No)]
[InlineData("unsupported", Supported.No)]
[InlineData("partial", Supported.Partial)]
[InlineData("yes", Supported.Yes)]
[InlineData("supported", Supported.Yes)]
public void AsSupportedTest(string? field, Supported expected)
{
Supported actual = field.AsSupported();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, SupportStatus.NULL)]
[InlineData("good", SupportStatus.Good)]
[InlineData("imperfect", SupportStatus.Imperfect)]
[InlineData("preliminary", SupportStatus.Preliminary)]
public void AsSupportStatusTest(string? field, SupportStatus expected)
{
SupportStatus actual = field.AsSupportStatus();
Assert.Equal(expected, actual);
}
#endregion
#region Enum to String
[Theory]
[InlineData(ChipType.NULL, null)]
[InlineData(ChipType.CPU, "cpu")]
[InlineData(ChipType.Audio, "audio")]
public void FromChipTypeTest(ChipType field, string? expected)
{
string? actual = field.AsStringValue<ChipType>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(ControlType.NULL, null)]
[InlineData(ControlType.Joy, "joy")]
[InlineData(ControlType.Stick, "stick")]
[InlineData(ControlType.Paddle, "paddle")]
[InlineData(ControlType.Pedal, "pedal")]
[InlineData(ControlType.Lightgun, "lightgun")]
[InlineData(ControlType.Positional, "positional")]
[InlineData(ControlType.Dial, "dial")]
[InlineData(ControlType.Trackball, "trackball")]
[InlineData(ControlType.Mouse, "mouse")]
[InlineData(ControlType.OnlyButtons, "only_buttons")]
[InlineData(ControlType.Keypad, "keypad")]
[InlineData(ControlType.Keyboard, "keyboard")]
[InlineData(ControlType.Mahjong, "mahjong")]
[InlineData(ControlType.Hanafuda, "hanafuda")]
[InlineData(ControlType.Gambling, "gambling")]
public void FromControlTypeTest(ControlType field, string? expected)
{
string? actual = field.AsStringValue<ControlType>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(DeviceType.NULL, null)]
[InlineData(DeviceType.Unknown, "unknown")]
[InlineData(DeviceType.Cartridge, "cartridge")]
[InlineData(DeviceType.FloppyDisk, "floppydisk")]
[InlineData(DeviceType.HardDisk, "harddisk")]
[InlineData(DeviceType.Cylinder, "cylinder")]
[InlineData(DeviceType.Cassette, "cassette")]
[InlineData(DeviceType.PunchCard, "punchcard")]
[InlineData(DeviceType.PunchTape, "punchtape")]
[InlineData(DeviceType.Printout, "printout")]
[InlineData(DeviceType.Serial, "serial")]
[InlineData(DeviceType.Parallel, "parallel")]
[InlineData(DeviceType.Snapshot, "snapshot")]
[InlineData(DeviceType.QuickLoad, "quickload")]
[InlineData(DeviceType.MemCard, "memcard")]
[InlineData(DeviceType.CDROM, "cdrom")]
[InlineData(DeviceType.MagTape, "magtape")]
[InlineData(DeviceType.ROMImage, "romimage")]
[InlineData(DeviceType.MIDIIn, "midiin")]
[InlineData(DeviceType.MIDIOut, "midiout")]
[InlineData(DeviceType.Picture, "picture")]
[InlineData(DeviceType.VidFile, "vidfile")]
public void FromDeviceTypeTest(DeviceType field, string? expected)
{
string? actual = field.AsStringValue<DeviceType>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(DisplayType.NULL, null)]
[InlineData(DisplayType.Raster, "raster")]
[InlineData(DisplayType.Vector, "vector")]
[InlineData(DisplayType.LCD, "lcd")]
[InlineData(DisplayType.SVG, "svg")]
[InlineData(DisplayType.Unknown, "unknown")]
public void FromDisplayTypeTest(DisplayType field, string? expected)
{
string? actual = field.AsStringValue<DisplayType>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(Endianness.NULL, null)]
[InlineData(Endianness.Big, "big")]
[InlineData(Endianness.Little, "little")]
public void FromEndiannessTest(Endianness field, string? expected)
{
string? actual = field.AsStringValue<Endianness>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(FeatureStatus.NULL, null)]
[InlineData(FeatureStatus.Unemulated, "unemulated")]
[InlineData(FeatureStatus.Imperfect, "imperfect")]
public void FromFeatureStatusTest(FeatureStatus field, string? expected)
{
string? actual = field.AsStringValue<FeatureStatus>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(FeatureType.NULL, null)]
[InlineData(FeatureType.Protection, "protection")]
[InlineData(FeatureType.Palette, "palette")]
[InlineData(FeatureType.Graphics, "graphics")]
[InlineData(FeatureType.Sound, "sound")]
[InlineData(FeatureType.Controls, "controls")]
[InlineData(FeatureType.Keyboard, "keyboard")]
[InlineData(FeatureType.Mouse, "mouse")]
[InlineData(FeatureType.Microphone, "microphone")]
[InlineData(FeatureType.Camera, "camera")]
[InlineData(FeatureType.Disk, "disk")]
[InlineData(FeatureType.Printer, "printer")]
[InlineData(FeatureType.Lan, "lan")]
[InlineData(FeatureType.Wan, "wan")]
[InlineData(FeatureType.Timing, "timing")]
public void FromFeatureTypeTest(FeatureType field, string? expected)
{
string? actual = field.AsStringValue<FeatureType>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(ItemStatus.NULL, true, null)]
[InlineData(ItemStatus.NULL, false, null)]
[InlineData(ItemStatus.None, true, "no")]
[InlineData(ItemStatus.None, false, "none")]
[InlineData(ItemStatus.Good, true, "good")]
[InlineData(ItemStatus.Good, false, "good")]
[InlineData(ItemStatus.BadDump, true, "baddump")]
[InlineData(ItemStatus.BadDump, false, "baddump")]
[InlineData(ItemStatus.Nodump, true, "yes")]
[InlineData(ItemStatus.Nodump, false, "nodump")]
[InlineData(ItemStatus.Verified, true, "verified")]
[InlineData(ItemStatus.Verified, false, "verified")]
public void FromItemStatusTest(ItemStatus field, bool useSecond, string? expected)
{
string? actual = field.AsStringValue<ItemStatus>(useSecond);
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(ItemType.NULL, null)]
[InlineData(ItemType.Adjuster, "adjuster")]
[InlineData(ItemType.Analog, "analog")]
[InlineData(ItemType.Archive, "archive")]
[InlineData(ItemType.BiosSet, "biosset")]
[InlineData(ItemType.Blank, "blank")]
[InlineData(ItemType.Chip, "chip")]
[InlineData(ItemType.Condition, "condition")]
[InlineData(ItemType.Configuration, "configuration")]
[InlineData(ItemType.ConfLocation, "conflocation")]
[InlineData(ItemType.ConfSetting, "confsetting")]
[InlineData(ItemType.Control, "control")]
[InlineData(ItemType.DataArea, "dataarea")]
[InlineData(ItemType.Device, "device")]
[InlineData(ItemType.DeviceRef, "device_ref")]
[InlineData(ItemType.DipLocation, "diplocation")]
[InlineData(ItemType.DipSwitch, "dipswitch")]
[InlineData(ItemType.DipValue, "dipvalue")]
[InlineData(ItemType.Disk, "disk")]
[InlineData(ItemType.DiskArea, "diskarea")]
[InlineData(ItemType.Display, "display")]
[InlineData(ItemType.Driver, "driver")]
[InlineData(ItemType.Extension, "extension")]
[InlineData(ItemType.Feature, "feature")]
[InlineData(ItemType.File, "file")]
[InlineData(ItemType.Info, "info")]
[InlineData(ItemType.Input, "input")]
[InlineData(ItemType.Instance, "instance")]
[InlineData(ItemType.Media, "media")]
[InlineData(ItemType.Part, "part")]
[InlineData(ItemType.PartFeature, "part_feature")]
[InlineData(ItemType.Port, "port")]
[InlineData(ItemType.RamOption, "ramoption")]
[InlineData(ItemType.Release, "release")]
[InlineData(ItemType.ReleaseDetails, "release_details")]
[InlineData(ItemType.Rom, "rom")]
[InlineData(ItemType.Sample, "sample")]
[InlineData(ItemType.Serials, "serials")]
[InlineData(ItemType.SharedFeat, "sharedfeat")]
[InlineData(ItemType.Slot, "slot")]
[InlineData(ItemType.SlotOption, "slotoption")]
[InlineData(ItemType.SoftwareList, "softwarelist")]
[InlineData(ItemType.Sound, "sound")]
[InlineData(ItemType.SourceDetails, "source_details")]
public void FromItemTypeTest(ItemType field, string? expected)
{
string? actual = field.AsStringValue<ItemType>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(LoadFlag.NULL, null)]
[InlineData(LoadFlag.Load16Byte, "load16_byte")]
[InlineData(LoadFlag.Load16Word, "load16_word")]
[InlineData(LoadFlag.Load16WordSwap, "load16_word_swap")]
[InlineData(LoadFlag.Load32Byte, "load32_byte")]
[InlineData(LoadFlag.Load32Word, "load32_word")]
[InlineData(LoadFlag.Load32WordSwap, "load32_word_swap")]
[InlineData(LoadFlag.Load32DWord, "load32_dword")]
[InlineData(LoadFlag.Load64Word, "load64_word")]
[InlineData(LoadFlag.Load64WordSwap, "load64_word_swap")]
[InlineData(LoadFlag.Reload, "reload")]
[InlineData(LoadFlag.Fill, "fill")]
[InlineData(LoadFlag.Continue, "continue")]
[InlineData(LoadFlag.ReloadPlain, "reload_plain")]
[InlineData(LoadFlag.Ignore, "ignore")]
public void FromLoadFlagTest(LoadFlag field, string? expected)
{
string? actual = field.AsStringValue<LoadFlag>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(MachineType.None, true, "none")]
[InlineData(MachineType.None, false, "none")]
[InlineData(MachineType.Bios, true, "bios")]
[InlineData(MachineType.Bios, false, "bios")]
[InlineData(MachineType.Device, true, "dev")]
[InlineData(MachineType.Device, false, "device")]
[InlineData(MachineType.Mechanical, true, "mech")]
[InlineData(MachineType.Mechanical, false, "mechanical")]
public void FromMachineTypeTest(MachineType field, bool old, string? expected)
{
string? actual = field.AsStringValue<MachineType>(old);
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(OpenMSXSubType.NULL, null)]
[InlineData(OpenMSXSubType.Rom, "rom")]
[InlineData(OpenMSXSubType.MegaRom, "megarom")]
[InlineData(OpenMSXSubType.SCCPlusCart, "sccpluscart")]
public void FromOpenMSXSubTypeTest(OpenMSXSubType field, string? expected)
{
string? actual = field.AsStringValue<OpenMSXSubType>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(Relation.NULL, null)]
[InlineData(Relation.Equal, "eq")]
[InlineData(Relation.NotEqual, "ne")]
[InlineData(Relation.GreaterThan, "gt")]
[InlineData(Relation.LessThanOrEqual, "le")]
[InlineData(Relation.LessThan, "lt")]
[InlineData(Relation.GreaterThanOrEqual, "ge")]
public void FromRelationTest(Relation field, string? expected)
{
string? actual = field.AsStringValue<Relation>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(Runnable.NULL, null)]
[InlineData(Runnable.No, "no")]
[InlineData(Runnable.Partial, "partial")]
[InlineData(Runnable.Yes, "yes")]
public void FromRunnableTest(Runnable field, string? expected)
{
string? actual = field.AsStringValue<Runnable>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(SoftwareListStatus.None, "none")]
[InlineData(SoftwareListStatus.Original, "original")]
[InlineData(SoftwareListStatus.Compatible, "compatible")]
public void FromSoftwareListStatusTest(SoftwareListStatus field, string? expected)
{
string? actual = field.AsStringValue<SoftwareListStatus>();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(Supported.NULL, true, null)]
[InlineData(Supported.NULL, false, null)]
[InlineData(Supported.No, true, "unsupported")]
[InlineData(Supported.No, false, "no")]
[InlineData(Supported.Partial, true, "partial")]
[InlineData(Supported.Partial, false, "partial")]
[InlineData(Supported.Yes, true, "supported")]
[InlineData(Supported.Yes, false, "yes")]
public void FromSupportedTest(Supported field, bool useSecond, string? expected)
{
string? actual = field.AsStringValue<Supported>(useSecond);
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(SupportStatus.NULL, null)]
[InlineData(SupportStatus.Good, "good")]
[InlineData(SupportStatus.Imperfect, "imperfect")]
[InlineData(SupportStatus.Preliminary, "preliminary")]
public void FromSupportStatusTest(SupportStatus field, string? expected)
{
string? actual = field.AsStringValue<SupportStatus>();
Assert.Equal(expected, actual);
}
#endregion
#region Generators
[Theory]

View File

@@ -0,0 +1,591 @@
using SabreTools.Core.Tools;
using Xunit;
namespace SabreTools.DatItems.Test
{
public class ExtensionsTests
{
#region String to Enum
[Theory]
[InlineData(null, ChipType.NULL)]
[InlineData("cpu", ChipType.CPU)]
[InlineData("audio", ChipType.Audio)]
public void AsChipTypeTest(string? field, ChipType expected)
{
ChipType actual = field.AsChipType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, ControlType.NULL)]
[InlineData("joy", ControlType.Joy)]
[InlineData("stick", ControlType.Stick)]
[InlineData("paddle", ControlType.Paddle)]
[InlineData("pedal", ControlType.Pedal)]
[InlineData("lightgun", ControlType.Lightgun)]
[InlineData("positional", ControlType.Positional)]
[InlineData("dial", ControlType.Dial)]
[InlineData("trackball", ControlType.Trackball)]
[InlineData("mouse", ControlType.Mouse)]
[InlineData("only_buttons", ControlType.OnlyButtons)]
[InlineData("keypad", ControlType.Keypad)]
[InlineData("keyboard", ControlType.Keyboard)]
[InlineData("mahjong", ControlType.Mahjong)]
[InlineData("hanafuda", ControlType.Hanafuda)]
[InlineData("gambling", ControlType.Gambling)]
public void AsControlTypeTest(string? field, ControlType expected)
{
ControlType actual = field.AsControlType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, DeviceType.NULL)]
[InlineData("unknown", DeviceType.Unknown)]
[InlineData("cartridge", DeviceType.Cartridge)]
[InlineData("floppydisk", DeviceType.FloppyDisk)]
[InlineData("harddisk", DeviceType.HardDisk)]
[InlineData("cylinder", DeviceType.Cylinder)]
[InlineData("cassette", DeviceType.Cassette)]
[InlineData("punchcard", DeviceType.PunchCard)]
[InlineData("punchtape", DeviceType.PunchTape)]
[InlineData("printout", DeviceType.Printout)]
[InlineData("serial", DeviceType.Serial)]
[InlineData("parallel", DeviceType.Parallel)]
[InlineData("snapshot", DeviceType.Snapshot)]
[InlineData("quickload", DeviceType.QuickLoad)]
[InlineData("memcard", DeviceType.MemCard)]
[InlineData("cdrom", DeviceType.CDROM)]
[InlineData("magtape", DeviceType.MagTape)]
[InlineData("romimage", DeviceType.ROMImage)]
[InlineData("midiin", DeviceType.MIDIIn)]
[InlineData("midiout", DeviceType.MIDIOut)]
[InlineData("picture", DeviceType.Picture)]
[InlineData("vidfile", DeviceType.VidFile)]
public void AsDeviceTypeTest(string? field, DeviceType expected)
{
DeviceType actual = field.AsDeviceType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, DisplayType.NULL)]
[InlineData("raster", DisplayType.Raster)]
[InlineData("vector", DisplayType.Vector)]
[InlineData("lcd", DisplayType.LCD)]
[InlineData("svg", DisplayType.SVG)]
[InlineData("unknown", DisplayType.Unknown)]
public void AsDisplayTypeTest(string? field, DisplayType expected)
{
DisplayType actual = field.AsDisplayType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, Endianness.NULL)]
[InlineData("big", Endianness.Big)]
[InlineData("little", Endianness.Little)]
public void AsEndiannessTest(string? field, Endianness expected)
{
Endianness actual = field.AsEndianness();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, FeatureStatus.NULL)]
[InlineData("unemulated", FeatureStatus.Unemulated)]
[InlineData("imperfect", FeatureStatus.Imperfect)]
public void AsFeatureStatusTest(string? field, FeatureStatus expected)
{
FeatureStatus actual = field.AsFeatureStatus();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, FeatureType.NULL)]
[InlineData("protection", FeatureType.Protection)]
[InlineData("palette", FeatureType.Palette)]
[InlineData("graphics", FeatureType.Graphics)]
[InlineData("sound", FeatureType.Sound)]
[InlineData("controls", FeatureType.Controls)]
[InlineData("keyboard", FeatureType.Keyboard)]
[InlineData("mouse", FeatureType.Mouse)]
[InlineData("microphone", FeatureType.Microphone)]
[InlineData("camera", FeatureType.Camera)]
[InlineData("disk", FeatureType.Disk)]
[InlineData("printer", FeatureType.Printer)]
[InlineData("lan", FeatureType.Lan)]
[InlineData("wan", FeatureType.Wan)]
[InlineData("timing", FeatureType.Timing)]
public void AsFeatureTypeTest(string? field, FeatureType expected)
{
FeatureType actual = field.AsFeatureType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, ItemStatus.NULL)]
[InlineData("none", ItemStatus.None)]
[InlineData("no", ItemStatus.None)]
[InlineData("good", ItemStatus.Good)]
[InlineData("baddump", ItemStatus.BadDump)]
[InlineData("nodump", ItemStatus.Nodump)]
[InlineData("yes", ItemStatus.Nodump)]
[InlineData("verified", ItemStatus.Verified)]
public void AsItemStatusTest(string? field, ItemStatus expected)
{
ItemStatus actual = field.AsItemStatus();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, ItemType.NULL)]
[InlineData("adjuster", ItemType.Adjuster)]
[InlineData("analog", ItemType.Analog)]
[InlineData("archive", ItemType.Archive)]
[InlineData("biosset", ItemType.BiosSet)]
[InlineData("blank", ItemType.Blank)]
[InlineData("chip", ItemType.Chip)]
[InlineData("condition", ItemType.Condition)]
[InlineData("configuration", ItemType.Configuration)]
[InlineData("conflocation", ItemType.ConfLocation)]
[InlineData("confsetting", ItemType.ConfSetting)]
[InlineData("control", ItemType.Control)]
[InlineData("dataarea", ItemType.DataArea)]
[InlineData("device", ItemType.Device)]
[InlineData("deviceref", ItemType.DeviceRef)]
[InlineData("device_ref", ItemType.DeviceRef)]
[InlineData("diplocation", ItemType.DipLocation)]
[InlineData("dipswitch", ItemType.DipSwitch)]
[InlineData("dipvalue", ItemType.DipValue)]
[InlineData("disk", ItemType.Disk)]
[InlineData("diskarea", ItemType.DiskArea)]
[InlineData("display", ItemType.Display)]
[InlineData("driver", ItemType.Driver)]
[InlineData("extension", ItemType.Extension)]
[InlineData("feature", ItemType.Feature)]
[InlineData("file", ItemType.File)]
[InlineData("info", ItemType.Info)]
[InlineData("input", ItemType.Input)]
[InlineData("instance", ItemType.Instance)]
[InlineData("media", ItemType.Media)]
[InlineData("part", ItemType.Part)]
[InlineData("partfeature", ItemType.PartFeature)]
[InlineData("part_feature", ItemType.PartFeature)]
[InlineData("port", ItemType.Port)]
[InlineData("ramoption", ItemType.RamOption)]
[InlineData("ram_option", ItemType.RamOption)]
[InlineData("release", ItemType.Release)]
[InlineData("releasedetails", ItemType.ReleaseDetails)]
[InlineData("release_details", ItemType.ReleaseDetails)]
[InlineData("rom", ItemType.Rom)]
[InlineData("sample", ItemType.Sample)]
[InlineData("serials", ItemType.Serials)]
[InlineData("sharedfeat", ItemType.SharedFeat)]
[InlineData("shared_feat", ItemType.SharedFeat)]
[InlineData("sharedfeature", ItemType.SharedFeat)]
[InlineData("shared_feature", ItemType.SharedFeat)]
[InlineData("slot", ItemType.Slot)]
[InlineData("slotoption", ItemType.SlotOption)]
[InlineData("slot_option", ItemType.SlotOption)]
[InlineData("softwarelist", ItemType.SoftwareList)]
[InlineData("software_list", ItemType.SoftwareList)]
[InlineData("sound", ItemType.Sound)]
[InlineData("sourcedetails", ItemType.SourceDetails)]
[InlineData("source_details", ItemType.SourceDetails)]
public void AsItemTypeTest(string? field, ItemType expected)
{
ItemType actual = field.AsItemType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, LoadFlag.NULL)]
[InlineData("load16_byte", LoadFlag.Load16Byte)]
[InlineData("load16_word", LoadFlag.Load16Word)]
[InlineData("load16_word_swap", LoadFlag.Load16WordSwap)]
[InlineData("load32_byte", LoadFlag.Load32Byte)]
[InlineData("load32_word", LoadFlag.Load32Word)]
[InlineData("load32_word_swap", LoadFlag.Load32WordSwap)]
[InlineData("load32_dword", LoadFlag.Load32DWord)]
[InlineData("load64_word", LoadFlag.Load64Word)]
[InlineData("load64_word_swap", LoadFlag.Load64WordSwap)]
[InlineData("reload", LoadFlag.Reload)]
[InlineData("fill", LoadFlag.Fill)]
[InlineData("continue", LoadFlag.Continue)]
[InlineData("reload_plain", LoadFlag.ReloadPlain)]
[InlineData("ignore", LoadFlag.Ignore)]
public void AsLoadFlagTest(string? field, LoadFlag expected)
{
LoadFlag actual = field.AsLoadFlag();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, MachineType.None)]
[InlineData("none", MachineType.None)]
[InlineData("bios", MachineType.Bios)]
[InlineData("dev", MachineType.Device)]
[InlineData("device", MachineType.Device)]
[InlineData("mech", MachineType.Mechanical)]
[InlineData("mechanical", MachineType.Mechanical)]
public void AsMachineTypeTest(string? field, MachineType expected)
{
MachineType actual = field.AsMachineType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, OpenMSXSubType.NULL)]
[InlineData("rom", OpenMSXSubType.Rom)]
[InlineData("megarom", OpenMSXSubType.MegaRom)]
[InlineData("sccpluscart", OpenMSXSubType.SCCPlusCart)]
public void AsOpenMSXSubTypeTest(string? field, OpenMSXSubType expected)
{
OpenMSXSubType actual = field.AsOpenMSXSubType();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, Relation.NULL)]
[InlineData("eq", Relation.Equal)]
[InlineData("ne", Relation.NotEqual)]
[InlineData("gt", Relation.GreaterThan)]
[InlineData("le", Relation.LessThanOrEqual)]
[InlineData("lt", Relation.LessThan)]
[InlineData("ge", Relation.GreaterThanOrEqual)]
public void AsRelationTest(string? field, Relation expected)
{
Relation actual = field.AsRelation();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, Runnable.NULL)]
[InlineData("no", Runnable.No)]
[InlineData("partial", Runnable.Partial)]
[InlineData("yes", Runnable.Yes)]
public void AsRunnableTest(string? field, Runnable expected)
{
Runnable actual = field.AsRunnable();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, SoftwareListStatus.None)]
[InlineData("none", SoftwareListStatus.None)]
[InlineData("original", SoftwareListStatus.Original)]
[InlineData("compatible", SoftwareListStatus.Compatible)]
public void AsSoftwareListStatusTest(string? field, SoftwareListStatus expected)
{
SoftwareListStatus actual = field.AsSoftwareListStatus();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, Supported.NULL)]
[InlineData("no", Supported.No)]
[InlineData("unsupported", Supported.No)]
[InlineData("partial", Supported.Partial)]
[InlineData("yes", Supported.Yes)]
[InlineData("supported", Supported.Yes)]
public void AsSupportedTest(string? field, Supported expected)
{
Supported actual = field.AsSupported();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(null, SupportStatus.NULL)]
[InlineData("good", SupportStatus.Good)]
[InlineData("imperfect", SupportStatus.Imperfect)]
[InlineData("preliminary", SupportStatus.Preliminary)]
public void AsSupportStatusTest(string? field, SupportStatus expected)
{
SupportStatus actual = field.AsSupportStatus();
Assert.Equal(expected, actual);
}
#endregion
#region Enum to String
[Theory]
[InlineData(ChipType.NULL, null)]
[InlineData(ChipType.CPU, "cpu")]
[InlineData(ChipType.Audio, "audio")]
public void FromChipTypeTest(ChipType field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(ControlType.NULL, null)]
[InlineData(ControlType.Joy, "joy")]
[InlineData(ControlType.Stick, "stick")]
[InlineData(ControlType.Paddle, "paddle")]
[InlineData(ControlType.Pedal, "pedal")]
[InlineData(ControlType.Lightgun, "lightgun")]
[InlineData(ControlType.Positional, "positional")]
[InlineData(ControlType.Dial, "dial")]
[InlineData(ControlType.Trackball, "trackball")]
[InlineData(ControlType.Mouse, "mouse")]
[InlineData(ControlType.OnlyButtons, "only_buttons")]
[InlineData(ControlType.Keypad, "keypad")]
[InlineData(ControlType.Keyboard, "keyboard")]
[InlineData(ControlType.Mahjong, "mahjong")]
[InlineData(ControlType.Hanafuda, "hanafuda")]
[InlineData(ControlType.Gambling, "gambling")]
public void FromControlTypeTest(ControlType field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(DeviceType.NULL, null)]
[InlineData(DeviceType.Unknown, "unknown")]
[InlineData(DeviceType.Cartridge, "cartridge")]
[InlineData(DeviceType.FloppyDisk, "floppydisk")]
[InlineData(DeviceType.HardDisk, "harddisk")]
[InlineData(DeviceType.Cylinder, "cylinder")]
[InlineData(DeviceType.Cassette, "cassette")]
[InlineData(DeviceType.PunchCard, "punchcard")]
[InlineData(DeviceType.PunchTape, "punchtape")]
[InlineData(DeviceType.Printout, "printout")]
[InlineData(DeviceType.Serial, "serial")]
[InlineData(DeviceType.Parallel, "parallel")]
[InlineData(DeviceType.Snapshot, "snapshot")]
[InlineData(DeviceType.QuickLoad, "quickload")]
[InlineData(DeviceType.MemCard, "memcard")]
[InlineData(DeviceType.CDROM, "cdrom")]
[InlineData(DeviceType.MagTape, "magtape")]
[InlineData(DeviceType.ROMImage, "romimage")]
[InlineData(DeviceType.MIDIIn, "midiin")]
[InlineData(DeviceType.MIDIOut, "midiout")]
[InlineData(DeviceType.Picture, "picture")]
[InlineData(DeviceType.VidFile, "vidfile")]
public void FromDeviceTypeTest(DeviceType field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(DisplayType.NULL, null)]
[InlineData(DisplayType.Raster, "raster")]
[InlineData(DisplayType.Vector, "vector")]
[InlineData(DisplayType.LCD, "lcd")]
[InlineData(DisplayType.SVG, "svg")]
[InlineData(DisplayType.Unknown, "unknown")]
public void FromDisplayTypeTest(DisplayType field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(Endianness.NULL, null)]
[InlineData(Endianness.Big, "big")]
[InlineData(Endianness.Little, "little")]
public void FromEndiannessTest(Endianness field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(FeatureStatus.NULL, null)]
[InlineData(FeatureStatus.Unemulated, "unemulated")]
[InlineData(FeatureStatus.Imperfect, "imperfect")]
public void FromFeatureStatusTest(FeatureStatus field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(FeatureType.NULL, null)]
[InlineData(FeatureType.Protection, "protection")]
[InlineData(FeatureType.Palette, "palette")]
[InlineData(FeatureType.Graphics, "graphics")]
[InlineData(FeatureType.Sound, "sound")]
[InlineData(FeatureType.Controls, "controls")]
[InlineData(FeatureType.Keyboard, "keyboard")]
[InlineData(FeatureType.Mouse, "mouse")]
[InlineData(FeatureType.Microphone, "microphone")]
[InlineData(FeatureType.Camera, "camera")]
[InlineData(FeatureType.Disk, "disk")]
[InlineData(FeatureType.Printer, "printer")]
[InlineData(FeatureType.Lan, "lan")]
[InlineData(FeatureType.Wan, "wan")]
[InlineData(FeatureType.Timing, "timing")]
public void FromFeatureTypeTest(FeatureType field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(ItemStatus.NULL, null)]
[InlineData(ItemStatus.None, "none")]
[InlineData(ItemStatus.Good, "good")]
[InlineData(ItemStatus.BadDump, "baddump")]
[InlineData(ItemStatus.Nodump, "nodump")]
[InlineData(ItemStatus.Verified, "verified")]
public void FromItemStatusTest(ItemStatus field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(ItemType.NULL, null)]
[InlineData(ItemType.Adjuster, "adjuster")]
[InlineData(ItemType.Analog, "analog")]
[InlineData(ItemType.Archive, "archive")]
[InlineData(ItemType.BiosSet, "biosset")]
[InlineData(ItemType.Blank, "blank")]
[InlineData(ItemType.Chip, "chip")]
[InlineData(ItemType.Condition, "condition")]
[InlineData(ItemType.Configuration, "configuration")]
[InlineData(ItemType.ConfLocation, "conflocation")]
[InlineData(ItemType.ConfSetting, "confsetting")]
[InlineData(ItemType.Control, "control")]
[InlineData(ItemType.DataArea, "dataarea")]
[InlineData(ItemType.Device, "device")]
[InlineData(ItemType.DeviceRef, "device_ref")]
[InlineData(ItemType.DipLocation, "diplocation")]
[InlineData(ItemType.DipSwitch, "dipswitch")]
[InlineData(ItemType.DipValue, "dipvalue")]
[InlineData(ItemType.Disk, "disk")]
[InlineData(ItemType.DiskArea, "diskarea")]
[InlineData(ItemType.Display, "display")]
[InlineData(ItemType.Driver, "driver")]
[InlineData(ItemType.Extension, "extension")]
[InlineData(ItemType.Feature, "feature")]
[InlineData(ItemType.File, "file")]
[InlineData(ItemType.Info, "info")]
[InlineData(ItemType.Input, "input")]
[InlineData(ItemType.Instance, "instance")]
[InlineData(ItemType.Media, "media")]
[InlineData(ItemType.Part, "part")]
[InlineData(ItemType.PartFeature, "part_feature")]
[InlineData(ItemType.Port, "port")]
[InlineData(ItemType.RamOption, "ramoption")]
[InlineData(ItemType.Release, "release")]
[InlineData(ItemType.ReleaseDetails, "release_details")]
[InlineData(ItemType.Rom, "rom")]
[InlineData(ItemType.Sample, "sample")]
[InlineData(ItemType.Serials, "serials")]
[InlineData(ItemType.SharedFeat, "sharedfeat")]
[InlineData(ItemType.Slot, "slot")]
[InlineData(ItemType.SlotOption, "slotoption")]
[InlineData(ItemType.SoftwareList, "softwarelist")]
[InlineData(ItemType.Sound, "sound")]
[InlineData(ItemType.SourceDetails, "source_details")]
public void FromItemTypeTest(ItemType field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(LoadFlag.NULL, null)]
[InlineData(LoadFlag.Load16Byte, "load16_byte")]
[InlineData(LoadFlag.Load16Word, "load16_word")]
[InlineData(LoadFlag.Load16WordSwap, "load16_word_swap")]
[InlineData(LoadFlag.Load32Byte, "load32_byte")]
[InlineData(LoadFlag.Load32Word, "load32_word")]
[InlineData(LoadFlag.Load32WordSwap, "load32_word_swap")]
[InlineData(LoadFlag.Load32DWord, "load32_dword")]
[InlineData(LoadFlag.Load64Word, "load64_word")]
[InlineData(LoadFlag.Load64WordSwap, "load64_word_swap")]
[InlineData(LoadFlag.Reload, "reload")]
[InlineData(LoadFlag.Fill, "fill")]
[InlineData(LoadFlag.Continue, "continue")]
[InlineData(LoadFlag.ReloadPlain, "reload_plain")]
[InlineData(LoadFlag.Ignore, "ignore")]
public void FromLoadFlagTest(LoadFlag field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(OpenMSXSubType.NULL, null)]
[InlineData(OpenMSXSubType.Rom, "rom")]
[InlineData(OpenMSXSubType.MegaRom, "megarom")]
[InlineData(OpenMSXSubType.SCCPlusCart, "sccpluscart")]
public void FromOpenMSXSubTypeTest(OpenMSXSubType field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(Relation.NULL, null)]
[InlineData(Relation.Equal, "eq")]
[InlineData(Relation.NotEqual, "ne")]
[InlineData(Relation.GreaterThan, "gt")]
[InlineData(Relation.LessThanOrEqual, "le")]
[InlineData(Relation.LessThan, "lt")]
[InlineData(Relation.GreaterThanOrEqual, "ge")]
public void FromRelationTest(Relation field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(Runnable.NULL, null)]
[InlineData(Runnable.No, "no")]
[InlineData(Runnable.Partial, "partial")]
[InlineData(Runnable.Yes, "yes")]
public void FromRunnableTest(Runnable field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(SoftwareListStatus.None, "none")]
[InlineData(SoftwareListStatus.Original, "original")]
[InlineData(SoftwareListStatus.Compatible, "compatible")]
public void FromSoftwareListStatusTest(SoftwareListStatus field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(Supported.NULL, true, null)]
[InlineData(Supported.NULL, false, null)]
[InlineData(Supported.No, true, "unsupported")]
[InlineData(Supported.No, false, "no")]
[InlineData(Supported.Partial, true, "partial")]
[InlineData(Supported.Partial, false, "partial")]
[InlineData(Supported.Yes, true, "supported")]
[InlineData(Supported.Yes, false, "yes")]
public void FromSupportedTest(Supported field, bool useSecond, string? expected)
{
string? actual = field.AsStringValue(useSecond);
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(SupportStatus.NULL, null)]
[InlineData(SupportStatus.Good, "good")]
[InlineData(SupportStatus.Imperfect, "imperfect")]
[InlineData(SupportStatus.Preliminary, "preliminary")]
public void FromSupportStatusTest(SupportStatus field, string? expected)
{
string? actual = field.AsStringValue();
Assert.Equal(expected, actual);
}
#endregion
}
}

View File

@@ -10,87 +10,172 @@ namespace SabreTools.DatItems
/// <summary>
/// Set of enum to string mappings for ChipType
/// </summary>
private static readonly Dictionary<string, ChipType> _chipTypeMap = Converters.GenerateToEnum<ChipType>();
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> _controlTypeMap = Converters.GenerateToEnum<ControlType>();
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> _deviceTypeMap = Converters.GenerateToEnum<DeviceType>();
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> _displayTypeMap = Converters.GenerateToEnum<DisplayType>();
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> _endiannessMap = Converters.GenerateToEnum<Endianness>();
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> _featureStatusMap = Converters.GenerateToEnum<FeatureStatus>();
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> _featureTypeMap = Converters.GenerateToEnum<FeatureType>();
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> _itemStatusMap = Converters.GenerateToEnum<ItemStatus>();
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> _itemTypeMap = Converters.GenerateToEnum<ItemType>();
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> _loadFlagMap = Converters.GenerateToEnum<LoadFlag>();
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> _machineTypeMap = Converters.GenerateToEnum<MachineType>();
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> _openMSXSubTypeMap = Converters.GenerateToEnum<OpenMSXSubType>();
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> _relationMap = Converters.GenerateToEnum<Relation>();
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> _runnableMap = Converters.GenerateToEnum<Runnable>();
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> _softwareListStatusMap = Converters.GenerateToEnum<SoftwareListStatus>();
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> _supportedMap = Converters.GenerateToEnum<Supported>();
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> _supportStatusMap = Converters.GenerateToEnum<SupportStatus>();
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
@@ -100,7 +185,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static ChipType AsChipType(this string? value)
{
@@ -110,8 +194,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_chipTypeMap.ContainsKey(value))
return _chipTypeMap[value];
if (_toChipTypeMap.ContainsKey(value))
return _toChipTypeMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -121,7 +205,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static ControlType AsControlType(this string? value)
{
@@ -131,8 +214,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_controlTypeMap.ContainsKey(value))
return _controlTypeMap[value];
if (_toControlTypeMap.ContainsKey(value))
return _toControlTypeMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -142,7 +225,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static DeviceType AsDeviceType(this string? value)
{
@@ -152,8 +234,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_deviceTypeMap.ContainsKey(value))
return _deviceTypeMap[value];
if (_toDeviceTypeMap.ContainsKey(value))
return _toDeviceTypeMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -163,7 +245,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static DisplayType AsDisplayType(this string? value)
{
@@ -173,8 +254,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_displayTypeMap.ContainsKey(value))
return _displayTypeMap[value];
if (_toDisplayTypeMap.ContainsKey(value))
return _toDisplayTypeMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -184,7 +265,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static Endianness AsEndianness(this string? value)
{
@@ -194,8 +274,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_endiannessMap.ContainsKey(value))
return _endiannessMap[value];
if (_toEndiannessMap.ContainsKey(value))
return _toEndiannessMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -205,7 +285,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static FeatureStatus AsFeatureStatus(this string? value)
{
@@ -215,8 +294,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_featureStatusMap.ContainsKey(value))
return _featureStatusMap[value];
if (_toFeatureStatusMap.ContainsKey(value))
return _toFeatureStatusMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -226,7 +305,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static FeatureType AsFeatureType(this string? value)
{
@@ -236,8 +314,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_featureTypeMap.ContainsKey(value))
return _featureTypeMap[value];
if (_toFeatureTypeMap.ContainsKey(value))
return _toFeatureTypeMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -247,7 +325,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static ItemStatus AsItemStatus(this string? value)
{
@@ -257,8 +334,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_itemStatusMap.ContainsKey(value))
return _itemStatusMap[value];
if (_toItemStatusMap.ContainsKey(value))
return _toItemStatusMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -268,7 +345,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static ItemType AsItemType(this string? value)
{
@@ -278,8 +354,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_itemTypeMap.ContainsKey(value))
return _itemTypeMap[value];
if (_toItemTypeMap.ContainsKey(value))
return _toItemTypeMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -289,7 +365,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static LoadFlag AsLoadFlag(this string? value)
{
@@ -299,8 +374,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_loadFlagMap.ContainsKey(value))
return _loadFlagMap[value];
if (_toLoadFlagMap.ContainsKey(value))
return _toLoadFlagMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -310,7 +385,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static MachineType AsMachineType(this string? value)
{
@@ -320,8 +394,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_machineTypeMap.ContainsKey(value))
return _machineTypeMap[value];
if (_toMachineTypeMap.ContainsKey(value))
return _toMachineTypeMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -331,7 +405,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static OpenMSXSubType AsOpenMSXSubType(this string? value)
{
@@ -341,8 +414,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_openMSXSubTypeMap.ContainsKey(value))
return _openMSXSubTypeMap[value];
if (_toOpenMSXSubTypeMap.ContainsKey(value))
return _toOpenMSXSubTypeMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -352,7 +425,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static Relation AsRelation(this string? value)
{
@@ -362,8 +434,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_relationMap.ContainsKey(value))
return _relationMap[value];
if (_toRelationMap.ContainsKey(value))
return _toRelationMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -373,7 +445,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static Runnable AsRunnable(this string? value)
{
@@ -383,8 +454,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_runnableMap.ContainsKey(value))
return _runnableMap[value];
if (_toRunnableMap.ContainsKey(value))
return _toRunnableMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -394,7 +465,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static SoftwareListStatus AsSoftwareListStatus(this string? value)
{
@@ -404,8 +474,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_softwareListStatusMap.ContainsKey(value))
return _softwareListStatusMap[value];
if (_toSoftwareListStatusMap.ContainsKey(value))
return _toSoftwareListStatusMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -415,7 +485,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static Supported AsSupported(this string? value)
{
@@ -425,8 +494,8 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_supportedMap.ContainsKey(value))
return _supportedMap[value];
if (_toSupportedMap.ContainsKey(value))
return _toSupportedMap[value];
// Otherwise, return the default value for the enum
return default;
@@ -436,7 +505,6 @@ namespace SabreTools.DatItems
/// Get the enum value for an input string, if possible
/// </summary>
/// <param name="value">String value to parse/param>
/// <typeparam name="T">Enum type that is expected</typeparam>
/// <returns>Enum value representing the input, default on error</returns>
public static SupportStatus AsSupportStatus(this string? value)
{
@@ -446,13 +514,275 @@ namespace SabreTools.DatItems
return default;
// Try to get the value from the mappings
if (_supportStatusMap.ContainsKey(value))
return _supportStatusMap[value];
if (_toSupportStatusMap.ContainsKey(value))
return _toSupportStatusMap[value];
// Otherwise, return the default value for the enum
return default;
}
#endregion
#region Enum to String
/// <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 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];
// 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 LoadFlag value)
{
// Try to get the value from the mappings
if (_fromLoadFlagMap.ContainsKey(value))
return _fromLoadFlagMap[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 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;
}
#endregion
}
}