1/// <summary>
2/// Converts the int to enum.
3/// </summary>
4/// <typeparam name="E">The enum type</typeparam>
5/// <param name="id">The id.</param>
6/// <param name="throwException">if set to <c>true</c> [throw exception].</param>
7/// <returns>
8/// The enum value represented by the supplied integer
9/// </returns>
10public static E ConvertIntToEnum<E>(int id, bool throwException)
11{
12 E enumValue = default(E);
13
14 if (Enum.IsDefined(typeof(E), id))
15 {
16 enumValue = (E)System.Enum.ToObject(typeof(E), id);
17 }
18 else
19 {
20 if (throwException)
21 {
22 throw new ArgumentException("Supplied enum id does not have a corrisponding enum");
23 }
24 }
25
26 return enumValue;
27}