I’m hosting IronPython 2.0 in a C#/Winforms application. I would like Python to be able to access various global, static objects in the host application.
As an example, the host application has an internal static class ‘Global’, which contains a number of static public members, which are are the various global objects I’d like to access:
static class Global { public static FeederSystem Feed ... public static LightingSystem Lighting ... public static IOSystem Io ... ... etc }
I want to be able to refer to Global.Lighting.xxx in Python code, just as I can in the C# application.
Is there an IronPythonic equivalent of ‘InternalsVisibleTo’ which I can use to allow Python code to see the internal types of the host application? Or do I need to make them all public?
Ok, so I worked this out myself, with the aid of the DLR spec, from here https://github.com/IronLanguages/dlr/blob/master/Docs/dlr-spec-hosting.pdf and by looking at the IP/DLR source.
This isn’t very elegant, and using a ScriptRuntimeSetup object with the PrivateBinding property set True would probably be a neater route than using CreateEngine.
But this one works: