diff --git a/ICD.Common.Utils/EnumUtils.cs b/ICD.Common.Utils/EnumUtils.cs index b0a7d70..03b6b90 100644 --- a/ICD.Common.Utils/EnumUtils.cs +++ b/ICD.Common.Utils/EnumUtils.cs @@ -305,6 +305,25 @@ namespace ICD.Common.Utils return GetFlags(value).Except(none); } + /// + /// Gets all of the flag combinations on the given flag enum value. + /// + /// IE: If you have an enum type with flags{a, b, c}, and you pass this method {a|b}, + /// It will return {a, b, a|b} + /// + /// + /// + /// + public static IEnumerable GetAllFlagCombinationsExceptNone(T value) + { + if (!IsEnum(value)) + // ReSharper disable once CompareNonConstrainedGenericWithNull + throw new ArgumentException(string.Format("{0} is not an enum", value == null ? "NULL" : value.GetType().Name), "value"); + + int maxEnumValue = (GetValues().Max(v => (int)(object)v) * 2) -1 ; + return Enumerable.Range(1, maxEnumValue).Cast().Where(v => HasFlags(value, v)); + } + /// /// Gets an enum value of the given type with every flag set. ///