/// <summary> /// Gets the description internal. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="val">The value.</param> /// <returns>EnumItem<T>.</returns> private static EnumItem <T> GetDescriptionInternal <T>(object val) { var field = val.GetType().GetField(val.ToString()); var attributes = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), false); var enumItem = new EnumItem <T> { Description = attributes.Length > 0 ? attributes[0].Description : val.ToString(), Value = (T)val }; return(enumItem); }
/// <summary> /// Gets the description of the enum value. /// </summary> /// <typeparam name="T">The type of T.</typeparam> /// <param name="val">The value.</param> /// <returns>EnumItem<T>.</returns> /// <exception cref="System.ArgumentNullException">The exception.</exception> private static EnumItem <T> GetDescriptionInternal <T>(object val) { if (val == null) { throw new ArgumentNullException(nameof(val), $"{nameof(val)} is null."); } var field = val.GetType().GetField(val.ToString()); var attributes = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), false); var enumItem = new EnumItem <T> { Description = attributes.Length > 0 ? attributes[0].Description : val.ToString(), Value = (T)val }; return(enumItem); }