我想用IronPython扩展我用C#编写的Windows Forms应用程序,使该软件的用户能够使用脚本扩展业务逻辑。我的想法是将一个强大的编辑器与语法突出显示和IntelliSense集成在一起。目前,我不知道应该使用哪个编辑器,也不知道如何从C#脚本访问用Python编写的程序集。有没有人知道,如果有任何教程,涵盖了这个问题,如果有任何在市场上,如果有任何组件,我可以集成到我的软件,以获得我需要的功能。
发布于 2017-03-22 16:54:56
从IronPython调用自己的程序集时,您不必执行任何操作,它使用反射来查找类型和成员
例如,我有一个类OrderPrice
public class OrderPrice
{
public decimal GetTotalPrice(Tariff.enumTariffType tariffType)
{
//....
}
}然后在C#中,我将变量价格添加到ScriptScope中
OrderPrice price = .....
ScriptScope scope = scriptEngine.CreateScope();
scope.SetVariable("price", price);然后在python脚本中,您只需调用所需的成员
if price.ErrorText == None:
totalType = price.GetTariffType()
totalPrice = price.GetTotalPrice(totalType)如果要从脚本实例化C#对象,则必须使用clr模块并添加dll作为引用
import clr
clr.AddReferenceToFileAndPath(r"Entities.dll")
from Entities import OrderPrice
o = OrderPrice()https://stackoverflow.com/questions/42946098
复制相似问题