2009-04-10 38 views
0

自定義.NET類型假設下面的代碼:實例化IronPython中

public class Foo 
{ 
    public string Bar { get; set; } 
} 

我怎樣才能在下面的代碼實例化美孚的一個實例?

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

回答

1
string script = @" 
    import clr 
    clr.AddReference('FooNamespace') 
    from FooNamespace import * 
    x = Foo()";