IronPython将.Net类型暴露给运行时引擎

Amy*_*Amy 5 .net ironpython dynamic-language-runtime

我希望将特定的.Net类型公开给IronPython运行时.我可以做这个:

ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
engine.Runtime.LoadAssembly(typeof(Program).Assembly); // current assembly with types
Run Code Online (Sandbox Code Playgroud)

但是这会将所有类型公开给运行时.是否可以选择性加载?

Ree*_*sey 2

不,您必须加载整个程序集。

这是由ScriptDomainManager内部管理的,它只保留已加载程序集的列表,而不保留类型。

最好的选择是让您的程序集仅公开您希望在 Python 环境中可用的类型,并将其余类型保留在内部。