Copy/Deepcopy C# lists
christoph.neyer@...
Is there a way to copy C# typed lists that I'm missing? Currently, the builtin copy/deepcopy fails, but I can workaround it by moving the items to a python list, deepcopying it and casting it back. Code: ``` import copy ``` ``` C#: List[Object_1$1]([<MyClass object at 0x0000000000000290>, <MyClass object at 0x0000000000000291>]) failed to deep copy: Type 'IronPython.NewTypes.System.Object_1$1' in Assembly 'Snippets.scripting, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable. Uncopied python list: [<MyClass object at 0x0000000000000290>, <MyClass object at 0x0000000000000291>] Copied python list: [<MyClass object at 0x000000000000029D>, <MyClass object at 0x000000000000029E>] Copied C# list: List[Object_1$1]([<MyClass object at 0x000000000000029D>, <MyClass object at 0x000000000000029E>]) ```
|
|
Stéphane Lozier
copy/deepcopy for "unknown" types use pickling and it looks like pickling of strongly typed generic lists using custom Python classes doesn't work properly (it becomes List[Object_1$1] instead of List[MyClass]). Converting to a Python list is one option, otherwise, you can try using the slicing notation (e.g. l2 = l1[:]) or a .NET method (e.g. List constructor or the .ToList() method of Linq). Stéphane
On Tue, Dec 17, 2019 at 8:24 PM <christoph.neyer@...> wrote:
|
|