1

I'm trying to send an array/list to an IronPython method as argument.

I can pass a normal array or list (and it works), but then native methods like pop are not available on the Python side.

What is the best way to convert a C# List<> to an IronPython.Runtime.List?

I found the IronPython.Runtime.List.__new__ method but I don't know how to fill CodeContext and PythonType variables.

I found this for the other way around: passing Lists from IronPython to C#

Dirk Boer
  • 8,522
  • 13
  • 63
  • 111

1 Answers1

0

Oops - found it. Just using an empty constructor():

public static IronPython.Runtime.List ToPythonList(this IEnumerable<object> list)
{
    var result = new IronPython.Runtime.List();

    foreach ( var item in list )
        result.append( item );

    return result;
}
Dirk Boer
  • 8,522
  • 13
  • 63
  • 111