如何使用 PythonNET 和 C#.NET 将枚举放入列表中?

How to put an Enum into a List, using PythonNET and C#.NET?

我有一个 NET 库,我正在使用 Python 和 PythonNET,但不知道如何将枚举放入列表中。似乎 Python 将枚举转换为不适合 List 数据类型的整数。这是一个例子:

import clr
from System.Collections.Generic import List
from System import Array, Enum
import MyLibrary

enum = List[MyLibrary.ResultType] #no errors here
enum.Add(MyLibrary.ResultType.PV) 
#TypeError: No method matches given arguments

#and just typing MyLibrary.ResultType.PV I get this result
Out[7]: 0

所以我也尝试创建一个数组 - 它也会创建一个具有枚举数据类型的空数组,但不允许我为其赋值:

Array[MyLibrary.ResultType](MyLibrary.ResultType.PV) 
#TypeError: Cannot convert 0 to MyLibrary.ResultType[]

谁有办法解决这个问题?欣赏一下。

天哪,我简直不敢相信我犯的错误,但就是这样。我没有通过初始化创建列表

enum = List[MyLibrary.ResultType]() #the missing () was the reason this didn't work!
enum.Add(MyLibrary.ResultType.PV)

现在一切正常。