diff --git a/ICD.Common.Utils/EnumUtils.cs b/ICD.Common.Utils/EnumUtils.cs index 461d7c7..de233ce 100644 --- a/ICD.Common.Utils/EnumUtils.cs +++ b/ICD.Common.Utils/EnumUtils.cs @@ -108,15 +108,31 @@ namespace ICD.Common.Utils return cache as T[]; } + /// + /// Gets the values from an enumeration without performing any caching. This is slow because of reflection. + /// + /// + public static IEnumerable GetValues(Type type) + { + return GetValuesUncached(type).Cast(); + } + /// /// Gets the values from an enumeration without performing any caching. This is slow because of reflection. /// /// private static IEnumerable GetValuesUncached() { - Type type = typeof(T); + return GetValuesUncached(typeof(T)).Cast(); + } - if (!IsEnumType()) + /// + /// Gets the values from an enumeration without performing any caching. This is slow because of reflection. + /// + /// + private static IEnumerable GetValuesUncached(Type type) + { + if (!IsEnumType(type)) throw new InvalidOperationException(string.Format("{0} is not an enum", type.Name)); return type @@ -126,8 +142,7 @@ namespace ICD.Common.Utils .GetTypeInfo() #endif .GetFields(BindingFlags.Static | BindingFlags.Public) - .Select(x => x.GetValue(null)) - .Cast(); + .Select(x => x.GetValue(null)); } /// @@ -140,6 +155,15 @@ namespace ICD.Common.Utils return GetFlagsExceptNone(); } + /// + /// Gets the values from an enumeration except the 0 value without performing any caching. This is slow because of reflection. + /// + /// + public static IEnumerable GetValuesExceptNone(Type type) + { + return GetValues(type).Except(0); + } + #endregion #region Flags @@ -151,10 +175,16 @@ namespace ICD.Common.Utils /// public static bool IsFlagsEnum() { - if (!IsEnumType()) - throw new ArgumentException(string.Format("{0} is not an enum", typeof(T).Name)); + return IsFlagsEnum(typeof(T)); + } - return typeof(T) + /// + /// Returns true if the given enum type has the Flags attribute set. + /// + /// + public static bool IsFlagsEnum(Type type) + { + return type #if !SIMPLSHARP .GetTypeInfo() #endif