假设以下代码:
public class Foo
{
public string Bar { get; set; }
}
如何在以下代码中实例化Foo实例?
ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null);
ScriptRuntime runtime = new ScriptRuntime(setup);
ScriptEngine engine = Python.GetEngine(runtime);
ScriptScope scope = engine.CreateScope();
string script = @"x = ***???***";
ScriptSource source = engine.CreateScriptSourceFromString(script, SourceCodeKind.Statements);
source.Execute(scope);
答案 0 :(得分:1)
string script = @"
import clr
clr.AddReference('FooNamespace')
from FooNamespace import *
x = Foo()";