-1

I've got dynamic object which contains some execute function generated by V8ScriptEngine. I need to execute this method with parameters which was specified in Dictionary object. I tried this approach:

private dynamic InvokeMethod(dynamic scriptObject, Dictionary<string, string> inpuValues)
{
        dynamic result;
        ((DynamicObject) scriptObject).TryInvoke(scriptObject.execute, inpuValues.Values.ToArray(), out result);
        return result;
}

but it throws

TypeError: Method or property not found

I also tried scriptObject.GetType().GetMethod("execute").Invoke with the same result But if i try to execute it manually (e.g scriptObject.execute(1,2)) it will return valid result. How can i invoke this method dynamically?

4

1 回答 1

1

过关怎么样IReflect

var result = ((IReflect)scriptObject).InvokeMember(
    "execute",
    BindingFlags.InvokeMethod, null, null,
    inpuValues.Values.Cast<object>().ToArray(),
    null, null, null);
于 2016-10-08T01:53:46.053 回答