using System;
using System.Collections;
using System.Linq;
namespace Neo.Afx.ComponentModel
{
///
/// Contains Enum extensions methods
///
public static partial class Extensions
{
#region GetValues
///
/// Retrieves an array of the values of the constants in a specified enumeration.
///
/// The type of the enum.
///
/// An array that contains the values of the constants in enum type
///
public static IEnumerable GetValues(this Enum enumType)
{
return enumType.GetType().GetValues();
}
///
/// Retrieves an array of the values of the constants in a specified enumeration.
///
/// The type of the enum.
///
/// An array that contains the values of the constants in enum type
///
public static IEnumerable GetValues(this Type enumType)
{
if(!enumType.IsEnum)
{
throw new ArgumentException("Type '" + enumType.Name + "' is not an enum");
}
var fields = from field in enumType.GetFields()
where field.IsLiteral
select field.GetValue(enumType);
return fields.ToList();
}
#endregion
}
}