[電繪]:Rattus rattus-黑鼠
In some eras, rats represented the plague and were despised creatures, but in my eyes, humans and rats are no different. -- 在某些時代裡,老鼠代表著瘟疫,是人們唾棄的生物,然而在我眼裡,人與老鼠並無不同。
取得Enum Description(描素)的值。
(1)建立EnumHelper:
/// <summary>
/// 取得列舉描述
/// </summary>
/// <param name="obj">列舉物件</param>
/// <returns></returns>
public static string GetDescription(this Enum obj)
{
var objName = obj.ToString();
var t = obj.GetType();
var fi = t.GetField(objName);
var arrayDescription = (DisplayAttribute[])fi.GetCustomAttributes(typeof(DisplayAttribute), false);
return arrayDescription == null ? string.Empty : arrayDescription[0].Description;
}
(2)使用範例:
留言
張貼留言