Custom Serialization

J

Jon Slaughter

BTW, I'm not quite sure why lines such as
......................CGCollections, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null.....rGCollections.RTree`1[[System.String, mscorlib,
Version=2.0.0.0, Culture=neutral,


exist since surely you have to know the object type at compile time to use
it properly? Sure you can load it into a system.object but what could will
that do? So at some point you have to know the right type and hence that
type should know how to load itself?

What I'm saying is that it would seem defining the object in the
serialization is unnecessary since you must have the definition in the
source and you shouldn't be loading random files up without really knowing
what they are in the first place?

Or is there some special reason for this? Sure it makes it easier to
understand but it seems extremely bloated.

Is there something I'm missing?
 
J

Jon Slaughter

I have a recursive class that looks like

[Serializable]

public class RTree<T> : IEnumerable<RTree<T>>, ISerializable

{

public List<RTree<T>> Nodes; // Container for Nodes

public T Value; // Value at this node

public RTree<T> Parent; // Contains the parent node

....



So its "recursive". The problem is that when I use the default serialization
of the class I get about 100x bloating than I need cause it tries to
describe all the objects in the class. Here is the output for a simple Rtree
using short strings,



.......................CGCollections, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null.....rGCollections.RTree`1[[System.String, mscorlib,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]].....Nodes.Value.Parent.....System.Collections.Generic.List`1[[GCollections.RTree`1[[System.String,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]], GCollections, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null]]rGCollections.RTree`1[[System.String,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]]...................Start........System.Collections.Generic.List`1[[GCollections.RTree`1[[System.String,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]], GCollections, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=null]]....._items._size._version...tGCollections.RTree`1[[System.String,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]][]..................................rGCollections.RTree`1[[System.String,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]]...................................................1................



So I want to serialize it my own way but I don't know how to go about it. I
also want to be able to serialize the generic type but I need to be able to
handle the "standard" way. Also I will, of course, want the ability to use
the binary and xml format.

Can this be done with ISerilizable? Do I need to create my own interface
and/or methods or what? I know I can write a method such as WriteToFile that
will dump the tree to file using my own way of organizing but I'd like to
somehow keep it within the ISerializable framework if possible.



Thanks,

Jon
 
J

Jon Slaughter

......................CGCollections, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null.....rGCollections.RTree`1[[System.String, mscorlib,
Version=2.0.0.0, Culture=neutral,
.................................................

BTW, I didn't mention this but the real issue is that this definition stuff
is repeated for every child RTRee. This means there is a lot of wasted space
since it just repeats the same thing over and over and over instead of once
at the begining.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top