Skip to content

Commit

Permalink
Use anonymous type insstead of dict for serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
zadockmaloba committed May 1, 2024
1 parent 593efe2 commit 7607029
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions RPCRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


using System;
using System.Text.Json;

public delegate void RPCRequestCallback(RPCResponse response);

Expand Down Expand Up @@ -63,26 +64,16 @@ public override string ToString()
return $"RPCRequest: Method={Method}, Params={Params}, Id={Id}";
}

public Dictionary<string, object> Serialize()
public string Serialize()
{
var payload = new Dictionary<string, object>();
if (!string.IsNullOrEmpty(Version))
{
payload["jsonrpc"] = Version;
}
if (!string.IsNullOrEmpty(Method))
{
payload["method"] = Method;
}
if (Params != null)
{
payload["params"] = Params;
}
if (!string.IsNullOrEmpty(Id))
{
payload["id"] = Id;
}
return payload;
var payload = new {
jsonrpc = Version,
method = Method,
id = Id,
@params = Params
};
var v = JsonSerializer.Serialize(payload);
return v;
}

~RPCRequest()
Expand Down

0 comments on commit 7607029

Please sign in to comment.