I\'d like one general purpose function that could be used with any Flags style enum to see if a flag exists.
This doesn\'t compile, but if anyone has a suggestion, I
Today, you can set the c# language version to >=7.3 and use the next code as the reference:
public static class EnumExt
{
public static IEnumerable Explode(this TEnum enumValue) where TEnum : Enum
{
var res = Enum.GetValues(enumValue.GetType())
.Cast()
.Where(x => enumValue.HasFlag(x));
return res;
}
public static string ExplodeToString(this TEnum enumValue, string delimeter = ",") where TEnum : Enum
{
return string.Join(delimeter, Explode(enumValue));
}
}