[IronPython] How to place static class in script name space

Markus Schaber m.schaber at 3s-software.com
Tue Jun 14 09:01:07 CEST 2011

Hi, Tom,

Von: Tom Unger

> But I want to eliminate the need for each script to do that import by setting up the scope with:
> scriptScope.SetVariable("App", App);
> This does not compile because App is a static class, not an object.  

Maybe scriptScope.SetVariable("App", DynamicHelpers.GetPythonTypeFromType(typeof(App))) can help here?

The C# typeof() operator returns the .NET type object (the same as you get from GetType() of an instance), and the DynamicHelpers.GetPythonTypeFromType() method returns the corresponding python type object for that .NET type.

I successfully used it to expose types (constructors, static members) to IronPython 2.6 scripts.

(DynamicHelpers is defined in the IronPython.Runtime.Types namespace.)



More information about the Ironpython-users mailing list