本文介绍了IronPython将.Net类型公开给运行时引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向IronPython运行时公开特定的.Net类型.我可以这样做:

I'm looking to expose specific .Net types to the IronPython runtime. I can do this:

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

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

But that exposes all types to the runtime. Is selective type loading possible?

推荐答案

否,您必须加载整个程序集.

No, you must load the entire assembly.

这由 ScriptDomainManager 内部管理.加载的程序集列表,而不是类型.

This is internally managed by the ScriptDomainManager, which only keeps a list of loaded assemblies, not types.

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

The best option would be to make your assembly only expose the types publicly that you want available within your Python environment, and leave the rest of the types internal.

这篇关于IronPython将.Net类型公开给运行时引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 16:15