• ResultData 返回数据类


    方便统一ashx返回类型~ weiapi也行~

    /// <summary>
        /// 返回数据
        /// </summary>
        public class ResultData
        {
            /// <summary>
            /// 操作状态
            /// </summary>
            public ResultDataStateEnum code { get; set; }
            /// <summary>
            /// 返回的数据集
            /// </summary>
            public dynamic data { get; set; }
            /// <summary>
            /// 信息
            /// </summary>
            public string msg { get; set; }
            /// <summary>
            /// 返回成功
            /// </summary>
            /// <param name="data"></param>
            /// <param name="message"></param>
            /// <returns></returns>
            public static ResultData Access()
            {
                var r = new ResultData()
                {
                    code = ResultDataStateEnum.正常
                };
                return r;
            }
            /// <summary>
            /// 返回成功
            /// </summary>
            /// <param name="data"></param>
            /// <param name="message"></param>
            /// <returns></returns>
            public static ResultData Access(string message)
            {
                var r = new ResultData()
                {
                    code = ResultDataStateEnum.正常,
                    msg = message
                };
                return r;
            }
            /// <summary>
            /// 返回成功
            /// </summary>
            /// <param name="data"></param>
            /// <param name="message"></param>
            /// <returns></returns>
            public static ResultData Access(dynamic data)
            {
                var r = new ResultData()
                {
                    code = ResultDataStateEnum.正常,
                    data = data
                };
                return r;
            }
            /// <summary>
            /// 返回失败
            /// </summary>
            /// <param name="message"></param>
            /// <returns></returns>
            public static ResultData Fail(string message = "")
            {
                var r = new ResultData()
                {
                    code = ResultDataStateEnum.错误,
                    msg = message
                };
                return r;
            }
            /// <summary>
            /// 返回失败
            /// </summary>
            /// <param name="message"></param>
            /// <returns></returns>
            public static ResultData Fail2(string message = "")
            {
                var r = new ResultData()
                {
                    code = ResultDataStateEnum.登录失败,
                    msg = message
                };
                return r;
            }
            /// <summary>
            /// 返回失败
            /// </summary>
            /// <param name="data"></param>
            /// <returns></returns>
            public static ResultData Fail(object data)
            {
                var r = new ResultData()
                {
                    code = ResultDataStateEnum.错误,
                    data = data
                };
                return r;
            }
    
            /// <summary>
            /// 将返回数据转为json字符串
            /// </summary>
            /// <param name="r"></param>
            /// <returns></returns>
            public static string toJson(ResultData r)
            {
                var model_JsonSerializerSettings = new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore,       //
                    DateFormatString = "yyyy-MM-dd HH:mm:ss"    //输出时间格式
                    //其他以后补充
                };
                return JsonConvert.SerializeObject(r, Formatting.Indented, model_JsonSerializerSettings);
            }
    
            public enum ResultDataStateEnum
            {
                登录失败 = -1,
                正常 = 0,
                错误 = 1,
                提示 = 2
            }
        }
  • 相关阅读:
    Css进阶
    Css布局
    遇到的小问题
    MySQL 8.017连接Navicat中出现的问题
    ConcurrentHashMap图文源码解析
    HashMap图文源码解析
    接口和抽象类
    dependencies 和 devDependencies
    2020.7.7第二天
    2020.7.6第一天
  • 原文地址:https://www.cnblogs.com/OleRookie/p/9153830.html
Copyright © 2020-2023  润新知