88 lines
2.5 KiB
C#
Raw Normal View History

2025-06-06 14:57:20 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YD_WeChatApplet.Commons.Enum;
namespace YD_WeChatApplet.Commons.Dto
{
public class WebResponseContent
{
public WebResponseContent()
{
}
public WebResponseContent(bool Success)
{
this.Success = Success;
}
public bool Success { get; set; }
public string ErrorCode { get; set; }
public string ErrorMsg { get; set; }
//public string ErrorMsg { get; set; }
public object Data { get; set; }
public WebResponseContent OK()
{
this.Success = true;
return this;
}
public static WebResponseContent Instance
{
get { return new WebResponseContent(); }
}
public WebResponseContent OK(string ErrorMsg = null, object data = null)
{
this.Success = true;
this.ErrorMsg = ErrorMsg;
this.Data = data;
return this;
}
public WebResponseContent OK(ResponseType responseType)
{
return Set(responseType, true);
}
public WebResponseContent Error(string ErrorMsg = null)
{
this.Success = false;
this.ErrorMsg = ErrorMsg;
return this;
}
public WebResponseContent Error(ResponseType responseType)
{
return Set(responseType, false);
}
public WebResponseContent Set(ResponseType responseType)
{
bool? b = null;
return this.Set(responseType, b);
}
public WebResponseContent Set(ResponseType responseType, bool? Success)
{
return this.Set(responseType, null, Success);
}
public WebResponseContent Set(ResponseType responseType, string msg)
{
bool? b = null;
return this.Set(responseType, msg, b);
}
public WebResponseContent Set(ResponseType responseType, string msg, bool? Success)
{
if (Success != null)
{
this.Success = (bool)Success;
}
this.ErrorCode = ((int)responseType).ToString();
if (!string.IsNullOrEmpty(msg))
{
ErrorMsg = msg;
return this;
}
ErrorMsg = responseType.GetMsg();
return this;
}
}
}