代码之家  ›  专栏  ›  技术社区  ›  Will Dean

如何从托管IronPython访问内部对象?

  •  1
  • Will Dean  · 技术社区  · 16 年前

    例如,主机应用程序有一个内部静态类“Global”,其中包含许多静态公共成员,这些成员是我想要访问的各种全局对象:

    static class Global
    {
      public static FeederSystem Feed ...
      public static LightingSystem Lighting ...
      public static IOSystem Io ...
      ... etc
    }
    

    我希望能够在Python代码中引用Global.Lighting.xxx,就像在C#应用程序中一样。

    是否有一个IronPythonic等效的“InternalsVisibleTo”,我可以使用它让Python代码查看宿主应用程序的内部类型?还是我需要把它们全部公开?

    1 回复  |  直到 16 年前
        1
  •  3
  •   wiz_lee    8 年前

    好的,我自己解决了这个问题,在DLR规范的帮助下,从这里开始 https://github.com/IronLanguages/dlr/blob/master/Docs/dlr-spec-hosting.pdf 通过查看IP/DLR源。

    但这一条有效:

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