diff --git a/ICD.Common.Utils/EnumUtils.cs b/ICD.Common.Utils/EnumUtils.cs index e27261d..b0a7d70 100644 --- a/ICD.Common.Utils/EnumUtils.cs +++ b/ICD.Common.Utils/EnumUtils.cs @@ -15,6 +15,7 @@ namespace ICD.Common.Utils public static class EnumUtils { private static readonly Dictionary s_EnumValuesCache; + private static readonly Dictionary> s_EnumFlagsCache; /// /// Static constructor. @@ -22,6 +23,7 @@ namespace ICD.Common.Utils static EnumUtils() { s_EnumValuesCache = new Dictionary(); + s_EnumFlagsCache = new Dictionary>(); } /// @@ -276,7 +278,15 @@ namespace ICD.Common.Utils // ReSharper disable once CompareNonConstrainedGenericWithNull throw new ArgumentException(string.Format("{0} is not an enum", value == null ? "NULL" : value.GetType().Name), "value"); - return GetValues().Where(e => HasFlag(value, e)); + Type type = typeof(T); + + if (!s_EnumFlagsCache.ContainsKey(type)) + s_EnumFlagsCache.Add(type, new Dictionary()); + + if (!s_EnumFlagsCache[type].ContainsKey(value)) + s_EnumFlagsCache[type][value] = GetValues().Where(e => HasFlag(value, e)).Cast().ToArray(); + + return s_EnumFlagsCache[type][value].Cast(); } ///