mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Remove redundant helper methods
This commit is contained in:
@@ -9,22 +9,6 @@ namespace SabreTools.Core.Tools
|
||||
{
|
||||
#region String to Enum
|
||||
|
||||
/// <summary>
|
||||
/// Get ChipType value from input string
|
||||
/// </summary>
|
||||
/// <param name="chipType">String to get value from</param>
|
||||
/// <returns>ChipType value corresponding to the string</returns>
|
||||
public static ChipType AsChipType(this string? chipType)
|
||||
=> AsEnumValue<ChipType>(chipType);
|
||||
|
||||
/// <summary>
|
||||
/// Get ControlType value from input string
|
||||
/// </summary>
|
||||
/// <param name="controlType">String to get value from</param>
|
||||
/// <returns>ControlType value corresponding to the string</returns>
|
||||
public static ControlType AsControlType(this string? controlType)
|
||||
=> AsEnumValue<ControlType>(controlType);
|
||||
|
||||
/// <summary>
|
||||
/// Get DatHeaderField value from input string
|
||||
/// </summary>
|
||||
@@ -85,78 +69,6 @@ namespace SabreTools.Core.Tools
|
||||
return AsEnumValue<DatItemField>(itemInput);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get DeviceType value from input string
|
||||
/// </summary>
|
||||
/// <param name="deviceType">String to get value from</param>
|
||||
/// <returns>DeviceType value corresponding to the string</returns>
|
||||
public static DeviceType AsDeviceType(this string? deviceType)
|
||||
=> AsEnumValue<DeviceType>(deviceType);
|
||||
|
||||
/// <summary>
|
||||
/// Get DisplayType value from input string
|
||||
/// </summary>
|
||||
/// <param name="displayType">String to get value from</param>
|
||||
/// <returns>DisplayType value corresponding to the string</returns>
|
||||
public static DisplayType AsDisplayType(this string? displayType)
|
||||
=> AsEnumValue<DisplayType>(displayType);
|
||||
|
||||
/// <summary>
|
||||
/// Get Endianness value from input string
|
||||
/// </summary>
|
||||
/// <param name="endianness">String to get value from</param>
|
||||
/// <returns>Endianness value corresponding to the string</returns>
|
||||
public static Endianness AsEndianness(this string? endianness)
|
||||
=> AsEnumValue<Endianness>(endianness);
|
||||
|
||||
/// <summary>
|
||||
/// Get FeatureStatus value from input string
|
||||
/// </summary>
|
||||
/// <param name="featureStatus">String to get value from</param>
|
||||
/// <returns>FeatureStatus value corresponding to the string</returns>
|
||||
public static FeatureStatus AsFeatureStatus(this string? featureStatus)
|
||||
=> AsEnumValue<FeatureStatus>(featureStatus);
|
||||
|
||||
/// <summary>
|
||||
/// Get FeatureType value from input string
|
||||
/// </summary>
|
||||
/// <param name="emulationStatus">String to get value from</param>
|
||||
/// <returns>FeatureType value corresponding to the string</returns>
|
||||
public static FeatureType AsFeatureType(this string? featureType)
|
||||
=> AsEnumValue<FeatureType>(featureType);
|
||||
|
||||
/// <summary>
|
||||
/// Get ItemStatus value from input string
|
||||
/// </summary>
|
||||
/// <param name="status">String to get value from</param>
|
||||
/// <returns>ItemStatus value corresponding to the string</returns>
|
||||
public static ItemStatus AsItemStatus(this string? status)
|
||||
=> AsEnumValue<ItemStatus>(status);
|
||||
|
||||
/// <summary>
|
||||
/// Get ItemType? value from input string
|
||||
/// </summary>
|
||||
/// <param name="itemType">String to get value from</param>
|
||||
/// <returns>ItemType? value corresponding to the string</returns>
|
||||
public static ItemType AsItemType(this string? itemType)
|
||||
=> AsEnumValue<ItemType>(itemType);
|
||||
|
||||
/// <summary>
|
||||
/// Get LoadFlag value from input string
|
||||
/// </summary>
|
||||
/// <param name="loadFlag">String to get value from</param>
|
||||
/// <returns>LoadFlag value corresponding to the string</returns>
|
||||
public static LoadFlag AsLoadFlag(this string? loadFlag)
|
||||
=> AsEnumValue<LoadFlag>(loadFlag);
|
||||
|
||||
/// <summary>
|
||||
/// Get LogLevel value from input string
|
||||
/// </summary>
|
||||
/// <param name="logLevel">String to get value from</param>
|
||||
/// <returns>LogLevel value corresponding to the string</returns>
|
||||
public static LogLevel AsLogLevel(this string? logLevel)
|
||||
=> AsEnumValue<LogLevel>(logLevel);
|
||||
|
||||
/// <summary>
|
||||
/// Get MachineField value from input string
|
||||
/// </summary>
|
||||
@@ -187,86 +99,6 @@ namespace SabreTools.Core.Tools
|
||||
return AsEnumValue<MachineField>(machineInput);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get MachineType value from input string
|
||||
/// </summary>
|
||||
/// <param name="gametype">String to get value from</param>
|
||||
/// <returns>MachineType value corresponding to the string</returns>
|
||||
public static MachineType AsMachineType(this string? gametype)
|
||||
=> AsEnumValue<MachineType>(gametype);
|
||||
|
||||
/// <summary>
|
||||
/// Get MergingFlag value from input string
|
||||
/// </summary>
|
||||
/// <param name="merging">String to get value from</param>
|
||||
/// <returns>MergingFlag value corresponding to the string</returns>
|
||||
public static MergingFlag AsMergingFlag(this string? merging)
|
||||
=> AsEnumValue<MergingFlag>(merging);
|
||||
|
||||
/// <summary>
|
||||
/// Get NodumpFlag value from input string
|
||||
/// </summary>
|
||||
/// <param name="nodump">String to get value from</param>
|
||||
/// <returns>NodumpFlag value corresponding to the string</returns>
|
||||
public static NodumpFlag AsNodumpFlag(this string? nodump)
|
||||
=> AsEnumValue<NodumpFlag>(nodump);
|
||||
|
||||
/// <summary>
|
||||
/// Get OpenMSXSubType value from input string
|
||||
/// </summary>
|
||||
/// <param name="subType">String to get value from</param>
|
||||
/// <returns>OpenMSXSubType value corresponding to the string</returns>
|
||||
public static OpenMSXSubType AsOpenMSXSubType(this string? subType)
|
||||
=> AsEnumValue<OpenMSXSubType>(subType);
|
||||
|
||||
/// <summary>
|
||||
/// Get PackingFlag value from input string
|
||||
/// </summary>
|
||||
/// <param name="packing">String to get value from</param>
|
||||
/// <returns>PackingFlag value corresponding to the string</returns>
|
||||
public static PackingFlag AsPackingFlag(this string? packing)
|
||||
=> AsEnumValue<PackingFlag>(packing);
|
||||
|
||||
/// <summary>
|
||||
/// Get Relation value from input string
|
||||
/// </summary>
|
||||
/// <param name="relation">String to get value from</param>
|
||||
/// <returns>Relation value corresponding to the string</returns>
|
||||
public static Relation AsRelation(this string? relation)
|
||||
=> AsEnumValue<Relation>(relation);
|
||||
|
||||
/// <summary>
|
||||
/// Get Runnable value from input string
|
||||
/// </summary>
|
||||
/// <param name="runnable">String to get value from</param>
|
||||
/// <returns>Runnable value corresponding to the string</returns>
|
||||
public static Runnable AsRunnable(this string? runnable)
|
||||
=> AsEnumValue<Runnable>(runnable);
|
||||
|
||||
/// <summary>
|
||||
/// Get SoftwareListStatus value from input string
|
||||
/// </summary>
|
||||
/// <param name="status">String to get value from</param>
|
||||
/// <returns>SoftwareListStatus value corresponding to the string</returns>
|
||||
public static SoftwareListStatus AsSoftwareListStatus(this string? status)
|
||||
=> AsEnumValue<SoftwareListStatus>(status);
|
||||
|
||||
/// <summary>
|
||||
/// Get Supported value from input string
|
||||
/// </summary>
|
||||
/// <param name="supported">String to get value from</param>
|
||||
/// <returns>Supported value corresponding to the string</returns>
|
||||
public static Supported AsSupported(this string? supported)
|
||||
=> AsEnumValue<Supported>(supported);
|
||||
|
||||
/// <summary>
|
||||
/// Get SupportStatus value from input string
|
||||
/// </summary>
|
||||
/// <param name="supported">String to get value from</param>
|
||||
/// <returns>SupportStatus value corresponding to the string</returns>
|
||||
public static SupportStatus AsSupportStatus(this string? supportStatus)
|
||||
=> AsEnumValue<SupportStatus>(supportStatus);
|
||||
|
||||
/// <summary>
|
||||
/// Get bool? value from input string
|
||||
/// </summary>
|
||||
@@ -288,7 +120,7 @@ namespace SabreTools.Core.Tools
|
||||
/// <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>
|
||||
internal static T? AsEnumValue<T>(string? value)
|
||||
public static T? AsEnumValue<T>(this string? value)
|
||||
{
|
||||
// Get the mapping dictionary
|
||||
var mappings = GenerateToEnum<T>();
|
||||
@@ -353,171 +185,6 @@ namespace SabreTools.Core.Tools
|
||||
|
||||
#region Enum to String
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input ChipType
|
||||
/// </summary>
|
||||
/// <param name="chipType">ChipType to get value from</param>
|
||||
/// <returns>String value corresponding to the ChipType</returns>
|
||||
public static string? FromChipType(this ChipType chipType)
|
||||
=> AsStringValue(chipType);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input ControlType
|
||||
/// </summary>
|
||||
/// <param name="controlType">ControlType to get value from</param>
|
||||
/// <returns>String value corresponding to the ControlType</returns>
|
||||
public static string? FromControlType(this ControlType controlType)
|
||||
=> AsStringValue(controlType);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input DeviceType
|
||||
/// </summary>
|
||||
/// <param name="deviceType">vDeviceType to get value from</param>
|
||||
/// <returns>String value corresponding to the DeviceType</returns>
|
||||
public static string? FromDeviceType(this DeviceType deviceType)
|
||||
=> AsStringValue(deviceType);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input DisplayType
|
||||
/// </summary>
|
||||
/// <param name="displayType">DisplayType to get value from</param>
|
||||
/// <returns>String value corresponding to the DisplayType</returns>
|
||||
public static string? FromDisplayType(this DisplayType displayType)
|
||||
=> AsStringValue(displayType);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input Endianness
|
||||
/// </summary>
|
||||
/// <param name="endianness">Endianness to get value from</param>
|
||||
/// <returns>String value corresponding to the Endianness</returns>
|
||||
public static string? FromEndianness(this Endianness endianness)
|
||||
=> AsStringValue(endianness);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input FeatureStatus
|
||||
/// </summary>
|
||||
/// <param name="featureStatus">FeatureStatus to get value from</param>
|
||||
/// <returns>String value corresponding to the FeatureStatus</returns>
|
||||
public static string? FromFeatureStatus(this FeatureStatus featureStatus)
|
||||
=> AsStringValue(featureStatus);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input FeatureType
|
||||
/// </summary>
|
||||
/// <param name="featureType">FeatureType to get value from</param>
|
||||
/// <returns>String value corresponding to the FeatureType</returns>
|
||||
public static string? FromFeatureType(this FeatureType featureType)
|
||||
=> AsStringValue(featureType);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input ItemStatus
|
||||
/// </summary>
|
||||
/// <param name="status">ItemStatus to get value from</param>
|
||||
/// <param name="yesno">True to use Yes/No format instead</param>
|
||||
/// <returns>String value corresponding to the ItemStatus</returns>
|
||||
public static string? FromItemStatus(this ItemStatus status, bool yesno)
|
||||
=> AsStringValue(status, yesno);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input ItemType?
|
||||
/// </summary>
|
||||
/// <param name="itemType">ItemType? to get value from</param>
|
||||
/// <returns>String value corresponding to the ItemType?</returns>
|
||||
public static string? FromItemType(this ItemType itemType)
|
||||
=> AsStringValue(itemType);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input LoadFlag
|
||||
/// </summary>
|
||||
/// <param name="loadFlag">LoadFlag to get value from</param>
|
||||
/// <returns>String value corresponding to the LoadFlag</returns>
|
||||
public static string? FromLoadFlag(this LoadFlag loadFlag)
|
||||
=> AsStringValue(loadFlag);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input MachineType
|
||||
/// </summary>
|
||||
/// <param name="gametype">MachineType to get value from</param>
|
||||
/// <param name="romCenter">True to use old naming instead</param>
|
||||
/// <returns>String value corresponding to the MachineType</returns>
|
||||
public static string? FromMachineType(this MachineType gametype, bool old)
|
||||
=> AsStringValue(gametype, old);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input MergingFlag
|
||||
/// </summary>
|
||||
/// <param name="merging">MergingFlag to get value from</param>
|
||||
/// <param name="romCenter">True to use RomCenter naming instead</param>
|
||||
/// <returns>String value corresponding to the MergingFlag</returns>
|
||||
public static string? FromMergingFlag(this MergingFlag merging, bool romCenter)
|
||||
=> AsStringValue(merging, romCenter);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input NodumpFlag
|
||||
/// </summary>
|
||||
/// <param name="nodump">NodumpFlag to get value from</param>
|
||||
/// <returns>String value corresponding to the NodumpFlag</returns>
|
||||
public static string? FromNodumpFlag(this NodumpFlag nodump)
|
||||
=> AsStringValue(nodump);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input OpenMSXSubType
|
||||
/// </summary>
|
||||
/// <param name="subType">OpenMSXSubType to get value from</param>
|
||||
/// <returns>String value corresponding to the OpenMSXSubType</returns>
|
||||
public static string? FromOpenMSXSubType(this OpenMSXSubType subType)
|
||||
=> AsStringValue(subType);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input PackingFlag
|
||||
/// </summary>
|
||||
/// <param name="packing">PackingFlag to get value from</param>
|
||||
/// <param name="yesno">True to use Yes/No format instead</param>
|
||||
/// <returns>String value corresponding to the PackingFlag</returns>
|
||||
public static string? FromPackingFlag(this PackingFlag packing, bool yesno)
|
||||
=> AsStringValue(packing, yesno);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input Relation
|
||||
/// </summary>
|
||||
/// <param name="relation">Relation to get value from</param>
|
||||
/// <returns>String value corresponding to the Relation</returns>
|
||||
public static string? FromRelation(this Relation relation)
|
||||
=> AsStringValue(relation);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input Runnable
|
||||
/// </summary>
|
||||
/// <param name="runnable">Runnable to get value from</param>
|
||||
/// <returns>String value corresponding to the Runnable</returns>
|
||||
public static string? FromRunnable(this Runnable runnable)
|
||||
=> AsStringValue(runnable);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input SoftwareListStatus
|
||||
/// </summary>
|
||||
/// <param name="status">SoftwareListStatus to get value from</param>
|
||||
/// <returns>String value corresponding to the SoftwareListStatus</returns>
|
||||
public static string? FromSoftwareListStatus(this SoftwareListStatus status)
|
||||
=> AsStringValue(status);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input Supported
|
||||
/// </summary>
|
||||
/// <param name="supported">Supported to get value from</param>
|
||||
/// <param name="verbose">True to use verbose output, false otherwise</param>
|
||||
/// <returns>String value corresponding to the Supported</returns>
|
||||
public static string? FromSupported(this Supported supported, bool verbose)
|
||||
=> AsStringValue(supported, verbose);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input SupportStatus
|
||||
/// </summary>
|
||||
/// <param name="supportStatus">SupportStatus to get value from</param>
|
||||
/// <returns>String value corresponding to the SupportStatus</returns>
|
||||
public static string? FromSupportStatus(this SupportStatus supportStatus)
|
||||
=> AsStringValue(supportStatus);
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input bool?
|
||||
/// </summary>
|
||||
@@ -540,7 +207,7 @@ namespace SabreTools.Core.Tools
|
||||
/// <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>
|
||||
internal static string? AsStringValue<T>(T value, bool useSecond = false) where T : notnull
|
||||
public static string? AsStringValue<T>(this T value, bool useSecond = false) where T : notnull
|
||||
{
|
||||
// Get the mapping dictionary
|
||||
var mappings = GenerateToString<T>(useSecond);
|
||||
|
||||
Reference in New Issue
Block a user