C# Python将属性视为函数
我有一个用C#写的库,它是这样的C# Python将属性视为函数,c#,com,python-2.7,C#,Com,Python 2.7,我有一个用C#写的库,它是这样的 class FooCollection { private readonly FooBase _innerFoo; public FooCollection() { _innerFoo = new FooBase(); } public string this[int index] { get { return
class FooCollection
{
private readonly FooBase _innerFoo;
public FooCollection()
{
_innerFoo = new FooBase();
}
public string this[int index]
{
get { return _innerFoo._components[index].ComponentName; }
set
{
_innerFoo._components[index].ComponentName = value;
}
}
}
这个类是COM可见的,我试图从Python中使用它。
所以,这个命令有效
foo(1)
但是这个没有
foo(1) = 'SomeName'
它给我“无法分配调用函数”。我试过方括号[],但那不好。
除了我在C#中使用额外的“普通”方法来设置此属性之外,还有什么方法可以绕过此问题吗
我正在Python中使用pywin32-218 for COM
foo = win32com.client.Dispatch("Foo")
索引属性转换为
IL
,如
FooCollection.get_Item
和FooCollection.set_Item
,因此很可能位于最终COM对象中
我也翻译了
尝试使用这些函数调用
希望这有帮助 差不多吧。“设置”时没有下划线。我在Matlab中也有同样的问题,在那里我必须使用'.set('PropertyName',index,value')。非常感谢你!