Archived
1
0
Fork 0
forked from Moux23333/FreeSR
This repository has been archived on 2024-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
FreeSR/FreeSR.Dispatch/Util/DispatchResponseBuilder.cs
2024-01-27 21:06:07 +08:00

69 lines
1.7 KiB
C#

namespace FreeSR.Dispatch.Util
{
using Newtonsoft.Json.Linq;
internal class DispatchResponseBuilder
{
private readonly JObject _jsonObject;
private DispatchResponseBuilder()
{
_jsonObject = new JObject();
}
public string Build()
{
return _jsonObject.ToString();
}
public DispatchResponseBuilder Code(int code)
{
_jsonObject["code"] = code;
return this;
}
public DispatchResponseBuilder Retcode(int retcode)
{
_jsonObject["retcode"] = retcode;
return this;
}
public DispatchResponseBuilder Message(string message)
{
_jsonObject["message"] = message;
return this;
}
public DispatchResponseBuilder Boolean(string field, bool value)
{
_jsonObject[field] = value;
return this;
}
public DispatchResponseBuilder String(string field, string value)
{
_jsonObject[field] = value;
return this;
}
public DispatchResponseBuilder Int(string field, int value)
{
_jsonObject[field] = value;
return this;
}
public DispatchResponseBuilder Array(string field, JArray array)
{
_jsonObject[field] = array;
return this;
}
public DispatchResponseBuilder Object(string field, JObject jsonObject)
{
_jsonObject[field] = jsonObject;
return this;
}
public static DispatchResponseBuilder Create() => new DispatchResponseBuilder();
}
}