This repository has been archived on 2024-03-29. You can view files and clone it, but cannot push or open issues or pull requests.
FreeSR/FreeSR.Dispatch/Util/DispatchResponseBuilder.cs

70 lines
1.7 KiB
C#
Raw Normal View History

2024-01-27 13:06:07 +00:00
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();
}
}