Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Custom Serialization

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jon Slaughter - 29 Mar 2008 19:08 GMT
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
Jon Slaughter - 29 Mar 2008 19:32 GMT
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?
Jon Slaughter - 29 Mar 2008 19:44 GMT
> ......................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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.