不完全是紅寶石,下面的是什麼,我爲IronPython的(確保組件引用在前):
runtime = IronPython.Hosting.Python.CreateRuntime();
}
public void Run(string script, params object[] variables)
{
var scriptSource = runtime.GetEngineByFileExtension("py").CreateScriptSourceFromString(script, SourceCodeKind.Statements);
var scope = runtime.GetEngineByFileExtension("py").CreateScope();
foreach (var variable in variables)
foreach (var property in variable.GetType().GetProperties())
if (property.CanRead)
scope.SetVariable(property.Name, property.GetValue(variable, null));
scriptSource.Execute(scope);
這裏最重要的元素是腳本引擎。你可以通過不同的選項來請求它(在我的情況下是擴展名),並從內存或光盤源創建腳本。
也可以共享變量,這也會顯示出來。
我認爲現在在C#4.0中有一個更好的方法,因爲C#本身成爲一種動態編程語言。