mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-17 00:47:48 +01:00
39 lines
1.0 KiB
C#
39 lines
1.0 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace Flowframes.MiscUtils
|
|||
|
|
{
|
|||
|
|
internal class ParseUtils
|
|||
|
|
{
|
|||
|
|
public static TEnum GetEnum<TEnum>(string str, bool ignoreCase = true, Dictionary<string, string> stringMap = null) where TEnum : Enum
|
|||
|
|
{
|
|||
|
|
if (stringMap == null)
|
|||
|
|
stringMap = new Dictionary<string, string>();
|
|||
|
|
|
|||
|
|
str = stringMap.Get(str, true, true);
|
|||
|
|
var values = Enum.GetValues(typeof(TEnum)).Cast<TEnum>();
|
|||
|
|
|
|||
|
|
foreach (var entry in values)
|
|||
|
|
{
|
|||
|
|
string entryString = stringMap.Get(entry.ToString(), true);
|
|||
|
|
|
|||
|
|
if (ignoreCase)
|
|||
|
|
{
|
|||
|
|
if (entryString.Lower() == str.Lower())
|
|||
|
|
return entry;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
if (entryString == str)
|
|||
|
|
return entry;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return (TEnum)(object)(-1);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|