[Python.NET] Help with an ObservableCollection

[email protected] Mon, 08 May 2023 22:43:29 -0000
Newsgroups gmane.comp.python.dotnet
Message-ID <[email protected]>
Hi,

I'm newly trying to use python .NET to embed some C# dlls into my python program. I'm very new to anything .NET, so I apologize if this is a simple question. In order to execute part of the program I need to submit some information back to an object in one of the dlls. This class is expecting an ObservableCollection of objects. I tried submitting a python list, but got an error that it couldn't be converted to the correct type. Unfortunately I can't share the API I'm using for licensing reasons, but here's a short pseudo code of the C# (using 'vegetable' to stand in for some proprietary object types):

private ObservableCollection<VegetableRecord> vegetableRecords
private VegetableSequence VegetableSequence
....
newVegetableRecord1 = new VegetableRecord('Potato')
newVegetableRecord2 = new VegetableRecord('Carrot')
vegetableRecords.Add(newVegetableRecord1)
vegetableRecords.Add(newVegetableRecord2)
...
VegetableSequence.SequenceRecordSet = vegetableRecords


I'm trying to recreate this in python, essentially, using the VegetableRecord and VegetableSequence imported from the dll :
vegetableRecords = []
VegetableSequence = VegetableSequence()
....
newVegetableRecord1 = VegetableRecord('Potato')
newVegetableRecord2 = VegetableRecord('Carrot')
vegetableRecords.append(newVegetableRecord1)
vegetableRecords.append(newVegetableRecord2)
...
VegetableSequence.SequenceRecordSet = vegetableRecords

That fails with an error that is essentially:
TypeError: 'list' value cannot be converted to System.Collections.Generic.ICollection`1[VegetableRecord]

Any advice?

Thanks!

- Jesse
_______________________________________________
Python.NET mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/pythonnet.python.org/
Member address: [email protected]