Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python sees property as function

Tags:

c#

python-2.7

com

I have a library written in C# and it goes like this

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

And this class is COM visible and I'm trying to use it from Python. So, this command works

foo(1)

but this one doesn't

foo(1) = 'SomeName'

It gives me "can't assign to call function". I tried square brackets [], but that is no good. Is there any way to bypass this, except me making additional 'normal' method in C# to set this property?

I'm using pywin32-218 for COM in Python.

foo = win32com.client.Dispatch("Foo")
like image 372
gajo357 Avatar asked Sep 20 '26 08:09

gajo357


1 Answers

Indexed property translates into IL, like

FooCollection.get_Item and FooCollection.set_Item, so probabbly in the final COM object translated too.

Try to use these function calls.

Hope this helps.

like image 185
Tigran Avatar answered Sep 22 '26 22:09

Tigran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!