using System.Collections.Generic;
using SabreTools.Core.Tools;
namespace SabreTools.DatFiles
{
public static class Extensions
{
#region Private Maps
///
/// Set of enum to string mappings for MergingFlag
///
private static readonly Dictionary _toMergingFlagMap = Converters.GenerateToEnum();
///
/// Set of string to enum mappings for MergingFlag
///
private static readonly Dictionary _fromMergingFlagMap = Converters.GenerateToString(useSecond: false);
///
/// Set of string to enum mappings for MergingFlag (secondary)
///
private static readonly Dictionary _fromMergingFlagSecondaryMap = Converters.GenerateToString(useSecond: true);
///
/// Set of enum to string mappings for NodumpFlag
///
private static readonly Dictionary _toNodumpFlagMap = Converters.GenerateToEnum();
///
/// Set of string to enum mappings for NodumpFlag
///
private static readonly Dictionary _fromNodumpFlagMap = Converters.GenerateToString(useSecond: false);
///
/// Set of enum to string mappings for PackingFlag
///
private static readonly Dictionary _toPackingFlagMap = Converters.GenerateToEnum();
///
/// Set of string to enum mappings for PackingFlag
///
private static readonly Dictionary _fromPackingFlagMap = Converters.GenerateToString(useSecond: false);
///
/// Set of string to enum mappings for PackingFlag (secondary)
///
private static readonly Dictionary _fromPackingFlagSecondaryMap = Converters.GenerateToString(useSecond: true);
#endregion
#region String to Enum
///
/// Get the enum value for an input string, if possible
///
/// String value to parse/param>
/// Enum value representing the input, default on error
public static MergingFlag AsMergingFlag(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value == null)
return default;
// Try to get the value from the mappings
if (_toMergingFlagMap.ContainsKey(value))
return _toMergingFlagMap[value];
// Otherwise, return the default value for the enum
return default;
}
///
/// Get the enum value for an input string, if possible
///
/// String value to parse/param>
/// Enum value representing the input, default on error
public static NodumpFlag AsNodumpFlag(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value == null)
return default;
// Try to get the value from the mappings
if (_toNodumpFlagMap.ContainsKey(value))
return _toNodumpFlagMap[value];
// Otherwise, return the default value for the enum
return default;
}
///
/// Get the enum value for an input string, if possible
///
/// String value to parse/param>
/// Enum value representing the input, default on error
public static PackingFlag AsPackingFlag(this string? value)
{
// Normalize the input value
value = value?.ToLowerInvariant();
if (value == null)
return default;
// Try to get the value from the mappings
if (_toPackingFlagMap.ContainsKey(value))
return _toPackingFlagMap[value];
// Otherwise, return the default value for the enum
return default;
}
#endregion
#region Enum to String
///
/// Get the string value for an input enum, if possible
///
/// Enum value to parse/param>
/// True to use the second mapping option, if it exists
/// String value representing the input, default on error
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;
}
///
/// Get the string value for an input enum, if possible
///
/// Enum value to parse/param>
/// True to use the second mapping option, if it exists
/// String value representing the input, default on error
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;
}
///
/// Get the string value for an input enum, if possible
///
/// Enum value to parse/param>
/// True to use the second mapping option, if it exists
/// String value representing the input, default on error
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
}
}