I am trying to create an extension method that will return a List containing all the Description attributes for only the set values o
You can iterate all values from enum and then filter them that isn't contained into your input value.
public static List GetAttributesByFlags(this Enum arg) where T: Attribute
{
var type = arg.GetType();
var result = new List();
foreach (var item in Enum.GetValues(type))
{
var value = (Enum)item;
if (arg.HasFlag(value)) // it means that '(arg & value) == value'
{
var memInfo = type.GetMember(value.ToString())[0];
result.Add((T)memInfo.GetCustomAttribute(typeof(T), false));
}
}
return result;
}
And you get list of attributes that you want:
var arg = Result.Value1 | Result.Value4;
List attributes = arg.GetAttributesByFlags();