Reputation: 11
I want to extend my Windows Forms Application programmed in C# with IronPython to enable the users of the software to extend the business logic with scripts. My Idea is to integrate a powerful editor with syntax highlighting and IntelliSense. At the moment I have no idea which editor I should use and how to access my Assemblies programmed in C# from the Python Script. Does anyone know, if there is any Tutorial which covers this Issue or if there are any components available on the market, which I can integrate in my software to get the functionality I need.
Upvotes: 1
Views: 1140
Reputation: 9763
You dont have to do anything when calling your own assemblies from IronPython, it uses reflection to find types and members
For instance, I have a class OrderPrice
public class OrderPrice
{
public decimal GetTotalPrice(Tariff.enumTariffType tariffType)
{
//....
}
}
Then in C# I add the variable price to the ScriptScope
OrderPrice price = .....
ScriptScope scope = scriptEngine.CreateScope();
scope.SetVariable("price", price);
Then in the python script you just call the members needed
if price.ErrorText == None:
totalType = price.GetTariffType()
totalPrice = price.GetTotalPrice(totalType)
And if you want to instantiate C# objects from the script you must use the clr module and add dll's as reference
import clr
clr.AddReferenceToFileAndPath(r"Entities.dll")
from Entities import OrderPrice
o = OrderPrice()
Upvotes: 3