Serializing IronPython objects that inherit from CLR types

This may be a bit of a strange question, but is there a reliable way to serialize IronPython objects whose classes extend CLR types?

For instance:

class Foo(System.Collections.Generic.List[str]):
    def Test(self):
        print "test!"

System.Collections.Generic.List<string>is serialized using Pickle because it implements the interface ISerializable, but the emitted subclasses of serializable CLR types do not seem to work, and I get it ImportError: No module named Generic in mscorlib, Version=4at startup pickle.dumps(Foo()).

In addition, running the usual Formatter.Serialize(stream, object)gives me:

SystemError: Type 'IronPython.NewTypes.System.Collections.Generic.List`1_4$4' in Assembly Snippets.scripting, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

How can I serialize IronPython objects while working in a C # native environment?

+5
source share
2 answers

clrtype

IronPython Reflection API IronPython CLR Python . CLR Python . , Python CLR.

class shop(object):
  pass 

class cheese_shop(shop):
  def have_cheese(self, cheese_type):
    return False

class argument_clinic(object):
  def is_right_room(self, room=12):
    return "I've told you once"

import clr
print clr.GetClrType(shop).FullName
print clr.GetClrType(cheese_shop).FullName
print clr.GetClrType(argument_clinic).FullName 

, cheese_shop shop argument_clinic , CLR

, , , .

+2

, , , protobuf python ()? , . , #, , . , , protobuf-net DLR, .

, DTO, .

+2

All Articles