IronPython mapping .Net type for runtime engine

I want to show specific .Net types for the IronPython runtime. I can do it:

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

But it provides all types at runtime. Is custom type loading possible?

+5
source share
3 answers

No, you have to download the whole assembly.

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

The best option would be to make your assembly only open to the types you want to get in your Python environment and leave the rest of the types internal.

+2
source

, . DynamicHelpers.GetPythonTypeFromType(typeof (TypeToInject)), PythonType, . :

  • ScriptRuntime.Globals

  • ScriptScope - ,

  • PythonType.GetBuiltinModule(),

+3

#, :

ScriptScope scope = runtime.CreateScope(); //get a scope where we put in the stuff from the host
scope.SetVariable("lab", lab);

script

lab.AnyMethodOfYourObject()
0

All Articles