xxxxxxxxxx
/// <summary>
/// Convert int to enum
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="intValue"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static T GetEnumValue<T>(int intValue) where T : struct, IConvertible
{
if (!typeof(T).IsEnum)
{
throw new Exception("T must be an Enumeration type.");
}
var val = GetValues<T>().FirstOrDefault();
foreach (var enumValue in GetValues<T>())
{
if (!Convert.ToInt32(enumValue).Equals(intValue)) continue;
val = enumValue;
break;
}
return val;
}
xxxxxxxxxx
YourEnum foo = (YourEnum)Enum.ToObject(typeof(YourEnum) , yourInt);