You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
downkyi/DownKyi.Core/BiliApi/Models/BaseModel.cs

31 lines
1017 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Newtonsoft.Json;
namespace DownKyi.Core.BiliApi.Models
{
public abstract class BaseModel
{
public string ToString(string format = "")
{
// 设置为去掉null
var jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
switch (format)
{
case "":
return JsonConvert.SerializeObject(this);
case "F":
// 整理json格式
return JsonConvert.SerializeObject(this, Formatting.Indented);
case "N":
// 去掉null后转换为json字符串
return JsonConvert.SerializeObject(this, Formatting.None, jsonSetting);
case "FN":
case "NF":
return JsonConvert.SerializeObject(this, Formatting.Indented, jsonSetting);
default:
return ToString();
}
}
}
}