Hi I want to use Roslyn to scripting in my app. But I have new (September) version and I am confused. I want to execute file with some simply function. For example:
public int m(){
return 6;
}
I found some articles about it for example acticle. There is some way to do it, but in my version isn't Session.Create()
I want to use it like IronPython scripting
Something like:
var scriptEngine = new SciptEngine.ExecuteFile(fileWithFunction);
dynamic d = getFunction(m);
or
dynamic d = callFunction(m);
Is it possible or I must use IronPython scripting?
The API hasn't changed significantly since the original CTP that the article was written in. For your scenario:
var scriptEngine = new ScriptEngine();
var session = scriptEngine.CreateSession();
session.AddReference("System");
session.AddReference("System.Core");
session.Execute(@"public int m() { return 6; }");
int six = session.Execute<int>("m()");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With