using MES.Production.Entity.Enum; using Ant.API.Entities; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MES.Production.Entity { public class BaseResponseModel { private string _issuccess; /// /// 返回状态码 /// public string code { get { return _issuccess; } set { _issuccess = value; } } /// /// 初始返回接口响应编码 /// /// public void InitResultState(System.Enum e) { code = e.GetHashCode().ToString("D3"); message = GetEnumDesc(e); } /// /// 初始返回接口出现异常响应编码 /// /// public void InitResultState(Exception ex) { this.InitResultState(StateEnum.Exception); this.message = string.Format(this.message, ex.Message); } /// /// 获取枚举的描述信息 /// 添加人:季健国 /// 添加时间:2013-12-02 /// /// 传入枚举对象 /// 得到对应描述信息 public static String GetEnumDesc(System.Enum e) { var enumInfo = e.GetType().GetField(e.ToString()); var enumAttributes = (DescriptionAttribute[])enumInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); return enumAttributes.Length > 0 ? enumAttributes[0].Description : e.ToString(); } private string _message; /// /// 返回信息 /// public string message { get { return _message; } set { _message = value; } } private string _token; /// /// 用户凭证 /// public string token { get { return _token; } set { _token = value; } } } }