sharp-jsonrpc/Request.cs

36 lines
958 B
C#

using System;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace sharp.jsonrpc
{
public class Request {
[JsonPropertyAttribute("sharp.jsonrpc")]
public string jsonrpc { get; set; } = "2.0";
[JsonPropertyAttribute("id")]
public String id { get; set; } = "0";
[JsonPropertyAttribute("method")]
public String method { get; set; }
[JsonPropertyAttribute("params")]
public Dictionary<string,object> args { get; set; }
private Request(string method,Dictionary<String,object> args){
this.id = Environment.TickCount.ToString();
this.method = method;
this.args = args == null ? new Dictionary<string, object>() : new Dictionary<String, object>(args);
}
public static string Create(string method)
{
return Create(method, null);
}
public static string Create(string method,Dictionary<String,object> args){
Request r = new Request(method,args);
return JsonConvert.SerializeObject(r);
}
}
}