mirror of
https://github.com/dotnetcore/AgileConfig.git
synced 2026-10-28 04:29:49 +08:00
31 lines
727 B
C#
31 lines
727 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace AgileConfig.Server.Common
|
|
{
|
|
public static class EnumExt
|
|
{
|
|
public static string ToDesc(this Enum e)
|
|
{
|
|
var fi = e.GetType().GetField(e.ToString());
|
|
if (fi == null)
|
|
{
|
|
return "";
|
|
}
|
|
var attrs = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
|
if (attrs != null & attrs.Any())
|
|
{
|
|
return attrs.First().Description;
|
|
}
|
|
else
|
|
{
|
|
return e.ToString();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|