C# 从C访问IronPython类的属性时遇到问题#

C# 从C访问IronPython类的属性时遇到问题#,c#,python,dynamic,ironpython,scriptengine,C#,Python,Dynamic,Ironpython,Scriptengine,我有一些C#代码,用于实例化IronPython类并从中运行一些代码。讨论中的IronPython类实现了一个在C#中定义的接口。它还定义了自己的一些属性 我在访问由类本身定义的属性时遇到问题,我想知道是否有人知道如何做到这一点 下面是一个示例IronPython类: import clr clr.AddReference('System.Core') from System import Tuple class TestClass (ITestInterface): ExampleP

我有一些C#代码,用于实例化IronPython类并从中运行一些代码。讨论中的IronPython类实现了一个在C#中定义的接口。它还定义了自己的一些属性

我在访问由类本身定义的属性时遇到问题,我想知道是否有人知道如何做到这一点

下面是一个示例IronPython类:

import clr
clr.AddReference('System.Core')
from System import Tuple

class TestClass (ITestInterface):
    ExamplePropertyOne = System.Tuple[System.String, System.String]("Hello", "World!")

    def ExampleMethod(self, some_parameter):
        ...code...
我创建了一个ScriptEngine对象来使用IronPython类,如下所示:

Dictionary<string, object> options = new Dictionary<string, object>();
options["Debug"] = true;
var python_script_engine = Python.CreateEngine(options);
var python_script_scope = python_script_engine.CreateScope();
python_script_engine.ExecuteFile("my_python_class.py", python_script_scope);

//The class could have any name, so instead of requesting the class by name,
//I simply iterate through the items in the python file to find the items
//that implements the expected interface, like so:
var python_script_items = python_script_scope.GetItems();
python_script_items = python_script_items.Where(x => x.Value is IronPython.Runtime.Types.PythonType);

foreach (var item in python_script_items)
{
    System.Type item_type = (Type)item.Value;
    var implemented_interfaces = item_type.GetInterfaces();
    if (implemented_interfaces != null && implemented_interfaces.Length > 0)
    {
        if (implemented_interfaces.ToList().Contains(typeof(ITestInterface)))
        {
            var class_to_instantiate = item.Value;
            var class_instance = class_to_instantiate();

            ...code here to get properties of class...
        }
    }
}
以上所有结果都不返回属性“ExamplePropertyOne”,它是“TestClass”的成员。我只能看到实现的方法。当然,python_脚本_scope.GetVariableNames只返回实例化类之外的范围的信息

那么,有什么建议吗?为什么我只能看到接口成员?如何访问类的属性

谢谢你的帮助

var list1 = Dynamic.GetMemberNames(class_instance);  //Using Dinamitey
var list2 = python_script_engine.Operations.GetMemberNames(class_instance);
var fields = item_type.GetFields();
var properties = item_type.GetProperties();
var attributes = item_type.CustomAttributes;
var attributes2 = item_type.GetCustomAttributes(false);
var members = item_type.GetMembers();
var var_names = python_script_scope.GetVariableNames();