2012-01-12 12 views
0

如何從C#中使用ScriptScope.SetVariable不使用ScriptEngine.ExecuteAndWrap("x = None", scope)設置一個變量的值的IronPython的範圍內爲無?變量是否需要在ScriptEngine/ScriptScope中定義?這個例子沒有工作:設置的IronPython的變量無

// Note: "scope" is the ScriptScope variable assigned beforehand 

scope.SetVariable("x", null); 

網絡搜索發現此相關的鏈接,但它沒有提供一個解決方案:
http://lists.ironpython.com/pipermail/users-ironpython.com/2009-June/010605.html

+0

在調用SetVariable之前,var不一定需要存在於範圍中。 – 2012-01-12 19:03:02

回答

1

據我所知道的關鍵字object僅僅是System.Object的別名,但我發現,鑄造nullSystem.Object在某些情況下工作。

scope.SetVariable("x", (Object)null); 
+0

謝謝!我也發現了var並不一定需要在範圍調用SetVariable之前存在。 – 2012-01-12 19:02:14

+0

工作就像一個魅力 – 2017-07-30 01:57:11