Revisit commented out public methods.
I would much much appreciate this being brought back even with the imperfect overload resolution.
Hi, Looks like CreateDelegate method is still not available in the latest version ( >= 2.4)?
I am looking to invoke a method described inside a script by the host application.
Any other way to achieve this?
This is very much similar to your existing test:
public void TestCreateMethodDelegate()
{
// create a delegate to a method declared in the script
var state = CSharpScript.Run("int Times(int x) { return x * x; }");
var fn = state.CreateDelegate
var result = fn(5);
Assert.Equal(25, result);
}
@ShekharGupta1988 Do you have a script that defines multiple methods and the host needs to chose some of them?
Hi @tmat - Yes. The script file would have multiple methods and host needs to execute one of those methods based on certain conditions.
You can work around the lack of CreateDelegate by creating delegates directly in the script:
C#
var state = await CSharpScript.RunAsync("var times = new System.Func<int, int>(x => x * x);");
var fn = (Func<int, int>)state.GetVariable("times").Value;
var result = fn(5);
@tmat - thanks for the work around :)
Most helpful comment
You can work around the lack of CreateDelegate by creating delegates directly in the script:
C# var state = await CSharpScript.RunAsync("var times = new System.Func<int, int>(x => x * x);"); var fn = (Func<int, int>)state.GetVariable("times").Value; var result = fn(5);