[Geek, obviously] Calling all C# Geeks

Apr 19, 2005 22:35


Question:

In Python there is a module called shelve, which effectively creates an on-disk dictionary into which one can save objects (of pretty much any type) against a string identifier. If I have object_1 which is an instance of class "fish" and object_2 which is an instance of class "apes" I can store each in the 'shelve' file using simple assignments:

StorageFile = shelve.open('/path/to/new/shelve/file.dat')
StorageFile['AnApeClassInstance'] = object_2
StorageFile['AFishClassInstance'] = object_1
StorageFile.close()

Later I can instantiate the things back out of the file by using assignements again (note the order of retrieval is unimportant, it's a random access file of records):

fishinstance = StorageFile['AFishClassInstance']
apeinstance = StorageFile['AnApeClassInstance']

Is there anything in the .NET framework or in some kind of C# library which emulates this behaviour, effectively allowing me to serialise objects to a random-access file? I specifically do not want to use the IStorage structured storage COM interface as provided by Win32 as this needs to be cross platform (if I use C# instead of Python it will be developed under Mono in Linux).

EDIT: I know I can bung everything into a superclass and serialise in one lump, but that rather defeats the object...

Previous post Next post
Up