Enum Extensions
This class contains two different methods to deal with enum types as IEnumerable<T> collections, where T is equals to the enum type.
Methods
Name
Parameters
Returns
Description
AsEnumerable
IEnumerable<T>
Cast a T enum to an IEnumerable which each element is an enum option.
AsEnumerableSkipZero
IEnumerable<T>
Cast a T enum to an IEnumerable which each element is an enum option, except by the zero value option.
Usage
You can transform an enum type defined by T to an IEnumerable<T>. Simplily executes the AsEnumerable method with enum type.
See the code bellow:
enum Options
{
None = 0,
FirstOption = 1,
SecondOption = 2,
ThirdOption = 3
}
IEnumerable<Options> result = EnumExtensions.AsEnumerable<Options>();
// result = [None, FirstOption, SecondOption, ThirdOption]You can ignore the zero value by using AsEnumerableSkipZero method, if you need.
enum Options
{
None = 0,
FirstOption = 1,
SecondOption = 2,
ThirdOption = 3
}
IEnumerable<Options> result = EnumExtensions.AsEnumerable<Options>();
// result = [FirstOption, SecondOption, ThirdOption]Last updated
Was this helpful?