Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: add function to scriptengine

0
0
Right, that won't work, assuming your code is as you posted it earlier.

If me represents a static method, first declare an appropriate delegate type:
publicdelegateobject StaticMethodFunc(paramsobject[] args);
Now you can expose a delegate that invokes the static method:
engine.AddHostObject(me.Name, new StaticMethodFunc(args => me.Invoke(null, args)));
By the way, if me represents an instance method, you can still expose a delegate that doesn't require an explicit target. All you have to do is provide the target in advance:
var target = Activator.CreateInstance(t);  // or create the target some other way
engine.AddHostObject(me.Name, new StaticMethodFunc(args => me.Invoke(target, args)));

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images