学无止境,精益求精
十年河东,十年河西,莫欺少年穷
用于基础返回值类型,如下:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Data.DataCommon { public class BaseResponse { public BaseResponse() { this.IsSuccess = false; this.ResultCode = -1; this.ResultMessage = "请求失败..."; } /// <summary> /// 返回信息 /// </summary> public string ResultMessage { get; set; } /// <summary> /// 返回编码 -1 代表失败 0代表成功 /// </summary> public int ResultCode { get; set; } /// <summary> /// 处理是否成功 /// </summary> public bool IsSuccess { get; set; } } public class BaseResponse<T> : BaseResponse { public T Data { get; set; } //public List<T> DataList { get; set; } public BaseResponse() { this.IsSuccess = false; this.ResultCode = -1; this.ResultMessage = "请求失败..."; } public BaseResponse(T data) { this.Data = data; } } public class CommonBaseResponse { #region 重置Response public static BaseResponse<T> SetResponse<T>(T Data, bool bol, string Msg = "", int cord = 0) { BaseResponse<T> response = new BaseResponse<T>(); response.Data = Data; response.IsSuccess = bol; response.ResultCode = bol == true ? 0 : -1; if (cord != 0) { response.ResultCode = cord; } response.ResultMessage = bol == true ? "请求成功..." : "请求失败..."; if (!string.IsNullOrEmpty(Msg)) { response.ResultMessage = Msg; } return response; } public static BaseResponse SetResponse(bool bol, string Msg = "", int cord = 0) { BaseResponse response = new BaseResponse(); response.IsSuccess = bol; response.ResultCode = bol == true ? 0 : -1; if (cord != 0) { response.ResultCode = cord; } response.ResultMessage = bol == true ? "请求成功..." : "请求失败..."; if (!string.IsNullOrEmpty(Msg)) { response.ResultMessage = Msg; } return response; } #endregion } }