0
try { Type type = typeof(Functions); MethodInfo method = type.GetMethod(msg); Functions c = new Functions(); ParameterInfo[] pars = method.GetParameters(); foreach (ParameterInfo p in pars) { send(p.ParameterType); } string result = (string)method.Invoke(c, null); send(result); } catch (Exception ex) { send(ex.Message); } 

So msg is string, I want to call function with parameters, for example like this:

string msg = "print(\"yes\")"; public class Functions { public string print(string text) { send(text); } } 

Currently if msg is equal to "print" it can execute simple print() function in Functions class:

public class Functions { public string print() { return "print() called"; } } 

code

But I don't know how to make it execute func with parameters, also get parameters from msg.

3
  • You can either parse the string yourself or use stackoverflow.com/questions/825107/… Commented Jan 3, 2020 at 21:41
  • What about Scripting API Samples Commented Jan 3, 2020 at 22:24
  • "get parameters from msg" is way too broad - so you have to figure out exactly what your requirements are and probably ask separate question on it. "execute func with parameters" is on other hand is properly scoped for SO and already answered in the linked duplicate. Commented Jan 3, 2020 at 23:24

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.