using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
/// <summary>
/// Contains <see cref="Enum"/> extension methods.
/// </summary>
public static class EnumExtensions
{
/// <summary>
/// Gets the Enum description attribute value.
/// </summary>
/// <param name="value">The enum value.</param>
/// <returns></returns>
public static String ToDescription(this Enum value)
{
FieldInfo fi = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attributes != null &&
attributes.Length > 0)
return attributes[0].Description;
else
return value.ToString();
}
public static T GetAttribute<T>(this Enum value) where T : Attribute
{
FieldInfo fi = value.GetType().GetField(value.ToString());
return fi.GetCustomAttribute<T>();
}
/// <summary>
/// Gets the enum integer value.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
public static int ToInt32(this Enum value)
{
return (int)((object)value);
}
/// <summary>
/// Gets all the flags from a bitwise enumeration.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="input">The enum.</param>
/// <returns></returns>
public static IEnumerable<T> GetFlags<T>(this Enum input)