I am evaluating AlterNet so my experience is limited. We want to expose application objects to Python script. However, we don’t want to expose all the methods in our objects to script. My first thought was to use an interface on the exposed class to “filter” what is exposed. I modified the Python.Wpf ObjectReference to try this. I created a class “ScriptApi” that has a method I don’t want to use in script. I then created an interface IScriptApi that does not include the “hidden” method. Then I passed the IScript API into a ScriptGlobalItem like this:
var api = (IScriptApi)new ScriptApi();
var item2 = new ScriptGlobalItem("Script", api);
scriptRun.GlobalItems.Clear();
scriptRun.GlobalItems.Add(item2);
When I test it, the Python script can see all the methods on ScriptApi.
Controlling access to our internal application objects is a critical feature for us. Our current scripting solution allows us to do that using a custom attribute that works on both classes and methods within the class. We could make “wrapper” objects to expose to the script but that would be a messy and inelegant solution. Is there a better one?
We have a similar requirement for classes to expose in script. Ideally, not every class in a given assembly would be visible in Python. Again, we can build separate assemblies that only contain the classes we want to expose but that will be a fairly significant refactoring of our application. Maybe we could leverage namespaces and imports to control this?
Thanks,
Nathan