sharp-jsonrpc/Request.cs

36 lines
958 B
C#
Raw Permalink Normal View History

2017-10-17 21:43:50 +02:00
using System;
2017-09-18 11:30:23 +02:00
using Newtonsoft.Json;
using System.Collections.Generic;
2017-10-17 21:43:50 +02:00
namespace sharp.jsonrpc
2017-09-18 11:30:23 +02:00
{
public class Request {
2017-10-17 21:43:50 +02:00
[JsonPropertyAttribute("sharp.jsonrpc")]
2017-09-18 11:30:23 +02:00
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);
}
}
}