C#基础之类方法使用关键词where和new,用于统一返回Json字符串数据
定义代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace code2._1
{
public class ReturnMessage<T> where T : new()
{
public string Message { get; set; }
public int Code { get; set; }
public List<object> Data { get; set; }
}
}
使用代码如下
context.Result = new JsonResult(new PetReturnMessage<object> //
{
Message = context.Exception.Message,
Code = context.HttpContext.Response.StatusCode,
Data = new List<object>()
});