嗨,我想使用Roslyn在我的应用程序中编写脚本。但是我有新的(9月)版本,我很困惑。我想用一些简单的函数来执行文件。例如:
public int m(){
return 6;
}我找到了一些关于它的文章,例如acticle。有一些方法可以做到这一点,但在我的版本中不是Session.Create(),我想像使用IronPython脚本一样使用它
类似于:
var scriptEngine = new SciptEngine.ExecuteFile(fileWithFunction);
dynamic d = getFunction(m);或
动态d= callFunction(m);
是否可以或必须使用IronPython脚本?
发布于 2012-09-27 11:10:42
自撰写本文的原始CTP以来,API并未发生重大变化。对于您的场景:
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()");https://stackoverflow.com/questions/12602922
复制相似问题