using System; using System.Collections.Generic; using System.Linq; namespace Flowframes.MiscUtils { internal class ParseUtils { public static TEnum GetEnum(string str, bool ignoreCase = true, Dictionary stringMap = null) where TEnum : Enum { if (stringMap == null) stringMap = new Dictionary(); str = stringMap.Get(str, true, true); var values = Enum.GetValues(typeof(TEnum)).Cast(); 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); } public static List GetEnumStrings() where TEnum : Enum { var entries = Enum.GetValues(typeof(TEnum)).Cast(); return entries.Select(e => e.ToString()).ToList(); } } }