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 _mergingFlagMap = Converters.GenerateToEnum();
///
/// Set of enum to string mappings for NodumpFlag
///
private static readonly Dictionary _nodumpFlagMap = Converters.GenerateToEnum();
///
/// Set of enum to string mappings for PackingFlag
///
private static readonly Dictionary _packingFlagMap = Converters.GenerateToEnum();
#endregion
#region String to Enum
///
/// Get the enum value for an input string, if possible
///
/// String value to parse/param>
/// Enum type that is expected
/// 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 (_mergingFlagMap.ContainsKey(value))
return _mergingFlagMap[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 type that is expected
/// 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 (_nodumpFlagMap.ContainsKey(value))
return _nodumpFlagMap[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 type that is expected
/// 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 (_packingFlagMap.ContainsKey(value))
return _packingFlagMap[value];
// Otherwise, return the default value for the enum
return default;
}
#endregion
}
}