IronPython:将 C# 列表转换为 IronPython.Runtime.List

IronPython: convert C# List to IronPython.Runtime.List

我正在尝试将 array/list 作为参数发送到 IronPython 方法。

我可以传递一个普通的数组或列表(并且有效),但是像 pop 这样的本地方法在 Python 端不可用。

将 C# List<> 转换为 IronPython.Runtime.List 的最佳方法是什么?

我找到了 IronPython.Runtime.List.__new__ 方法,但我不知道如何填充 CodeContextPythonType 变量。

我发现这个是相反的:passing Lists from IronPython to C#

糟糕 - 找到了。只使用一个空的构造函数():

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;
}