views:

124

answers:

1

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?

+2  A: 

Ok, so I worked this out myself, with the aid of the DLR spec, from here http://compilerlab.members.winisp.net/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:

Dictionary<string, object> options = new Dictionary<string, object>();
options.Add("PrivateBinding", true);

_engine = Python.CreateEngine(options);
Will Dean
good find, thanks!
Tom E