简体   繁体   中英

Roslyn Scripting

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()");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM