【发布时间】:2020-07-13 12:01:01
【问题描述】:
我的经理告诉我在从 Asp.net 核心项目中的 Web pi 控制器发回响应时使用以下类,现在我是编程新手并且对如何制作实例感到困惑,之后我可以将其转换为 JSON。我不知道只有 APIResponse 类的用法。
public class APIResponse<T>
{
public APIResponse()
: this(default(T))
{
}
public APIResponse(T data)
: this(ResponseCodes.RESPONSE_OK, ResponseMessages.RESPONSE_OK, data)
{
}
public APIResponse(int _code, string _msg, T _data)
{
this.code = _code;
this.msg = _msg;
this.data = _data;
}
public int code
{
get;
set;
}
public string msg
{
get;
set;
}
public T data
{
get;
set;
}
public int pageCount { get; set; }
public int pageSize { get; set; }
public int recordCount { get; set; }
}
【问题讨论】:
-
“创建实例”只是调用构造函数的意思。喜欢
new ApiResponse<string>(200, "Some message", "some string") -
感谢您的快速响应,但是通用对象呢,我实际上必须像我刚刚在问题中添加的图像一样发送响应。
标签: c# asp.net asp.net-web-api asp.net-core-webapi