学无止境,精益求精

十年河东,十年河西,莫欺少年穷

用于基础返回值类型,如下:

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
    }
}
View Code

相关文章:

  • 2021-09-25
  • 2022-12-23
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-26
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案