jeudi 19 janvier 2017

C# RPC expose API methods

Ok, so far, I have a way to expose some methods using this:

AddCommand ("UpdateStar", ((args) => {
   // do something
}));

It adds the command into a SortedDictionary<string, SimpleDelegate>. Here's my SimpleDelegate definition:

public delegate void SimpleDelegate(JSONNode args);

It's pretty straight forward, from Javascript I send a list of argument and in C# I receive a JSONNode which is a JSONArray. It's working but it's quite annoying to do things such as:

string name = args[0].Value;
int x = args[1].AsInt;
...

In the end, what I'd like to do is to instead expose actual methods in C# instead of exposing lambdas.

In other words, I'd like to do something like this:

[expose-to-rpc]
public void AddSystem(string name, int x, int y) {

}

It could find the name of the method, the number of argument and the type of arguments using reflection. I'm pretty sure something like that is possible but I'm kind of lost here. Not sure how to get started.





Aucun commentaire:

Enregistrer un commentaire