123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections.Generic;
- using System.Net;
- using System.Text;
- namespace XYY.Core.Standard.Mvc
- {
- /// <summary>
- /// 泛型对象
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public class ApiJsonModel<T>
- {
- /// <summary>
- /// 错误码(0表示无错误)
- /// </summary>
- public HttpStatusCode code { get; set; }
- /// <summary>
- /// 是否成功
- /// </summary>
- public bool success { get; set; }
- /// <summary>
- /// 错误信息
- /// </summary>
- public string error { get; set; }
- /// <summary>
- /// 消息
- /// </summary>
- public string message { get; set; }
- /// <summary>
- /// Json数据
- /// </summary>
- public T data { get; set; }
- public string Guid
- {
- get; set;
- }
- public static ApiJsonModel<T> OK(T data)
- {
- return new ApiJsonModel<T>
- {
- code = HttpStatusCode.OK,
- data = data,
- success = true,
- message = "成功"
- };
- }
- public static ApiJsonModel<T> Error(string message, T data)
- {
- return new ApiJsonModel<T>
- {
- code = HttpStatusCode.InternalServerError,
- data = data,
- success = false,
- message = message
- };
- }
- }
- [Serializable]
- public class ApiJsonModel : ApiJsonModel<object>
- {
- /// <summary>
- /// 错误码(0表示无错误)
- /// </summary>
- public HttpStatusCode code { get; set; }
- /// <summary>
- /// 是否成功
- /// </summary>
- public bool success { get; set; }
- /// <summary>
- /// 错误信息
- /// </summary>
- public string error { get; set; }
- /// <summary>
- /// 消息
- /// </summary>
- public string message { get; set; }
- /// <summary>
- /// Json数据
- /// </summary>
- public object data { get; set; }
- public static ApiJsonModel OK(object data = null)
- {
- return new ApiJsonModel
- {
- code = HttpStatusCode.OK,
- data = data,
- success = true,
- message = "成功"
- };
- }
- public static ApiJsonModel Error(string message, object data = null)
- {
- return new ApiJsonModel
- {
- code = HttpStatusCode.InternalServerError,
- data = data,
- success = false,
- message = message
- };
- }
- }
- }
|