[IronPython] Pickle-Serialization integration

Sanghyeon Seo sanxiyn at gmail.com
Wed Feb 7 06:52:28 CET 2007


Python has pickle, and .NET has System.Runtime.Serialization, and they
do roughly the same thing.

So one should be able to pickle any .NET objects that is serializable.

As Python's pickle has a mechanism to register custom hooks, I wrote
hooks to delegate pickling of .NET objects to
System.Runtime.Serialization. It works fine!

This is how it looks like:

from System import DateTime
import pickle
import fepy.pickle
fepy.pickle.register(DateTime)

obj = DateTime.Now
string = pickle.dumps(obj)
newobj = pickle.loads(string)
assert obj == newobj

Does it make to sense to do the reverse? That is, making picklable
Python objects serializable by, I guess, implementing ISerializable? I
have no idea how to go about that. Any suggestions welcome.

-- 
Seo Sanghyeon



More information about the Ironpython-users mailing list