1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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;
- /// <summary>
- /// 返回状态码
- /// </summary>
- public string code
- {
- get { return _issuccess; }
- set { _issuccess = value; }
- }
- /// <summary>
- /// 初始返回接口响应编码
- /// </summary>
- /// <param name="e"></param>
- public void InitResultState(System.Enum e)
- {
- code = e.GetHashCode().ToString("D3");
- message = GetEnumDesc(e);
- }
- /// <summary>
- /// 初始返回接口出现异常响应编码
- /// </summary>
- /// <param name="ex"></param>
- public void InitResultState(Exception ex)
- {
- this.InitResultState(StateEnum.Exception);
- this.message = string.Format(this.message, ex.Message);
- }
- /// <summary>
- /// 获取枚举的描述信息
- /// 添加人:季健国
- /// 添加时间:2013-12-02
- /// </summary>
- /// <param name="e">传入枚举对象</param>
- /// <returns>得到对应描述信息</returns>
- 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;
- /// <summary>
- /// 返回信息
- /// </summary>
- public string message
- {
- get { return _message; }
- set { _message = value; }
- }
- private string _token;
- /// <summary>
- /// 用户凭证
- /// </summary>
- public string token
- {
- get { return _token; }
- set { _token = value; }
- }
- }
- }
|