获取枚举的描述信息

	using System.ComponentModel;

    /// 
    /// 标签枚举
    /// 
    public enum StatusTag
    {
     
        /// 
        /// 正确
        /// 
        [Description("正确")]
        Success,
        /// 
        /// 错误
        /// 
        [Description("错误")]
        Error,
        /// 
        /// 警告
        /// 
        [Description("警告")]
        Warning
    }

获取枚举描述信息

  /// 
  /// 根据枚举值,获取Description
  /// 
  /// 
  /// 
  public static string Description(Enum value)
  {
     
      if (value == null)
          return "";
      var fieldInfo = value.GetType().GetField(value.ToString());
      var attribArray = fieldInfo.GetCustomAttributes(false);
      return attribArray.Length == 0 ? value.ToString() : (attribArray[0] as DescriptionAttribute).Description;
  }

你可能感兴趣的:(枚举)