Solved

How do I persist/serialize a Dictionary<String,ObjectClass> to a file in .Net C#?

Posted on 2013-01-14
2
655 Views
Last Modified: 2013-01-17
Hi:

I'm in the middle of designing/implementing saving my C# session to a file.

I'm looking for some help in direction of how to serialize/deserialize several
collections to a file. The file will contain a List<>, several Dictionary<> collections
and a blob of binary data.

I'm thinking that using XML would probably be easier?

What is the best way to proceed?
Are there some good/relevant samples I can look at?

This is what some of my collections look like:
====================================

private Dictionary<String, List<DModel.Entity_Fields>> dEntityFields;

private Dictionary<String, List<ComponentClass>> dComponents;

private Dictionary<String, int> dFieldLengths;

private binary blob of data;

Thanks,
JohnB
0
Comment
Question by:jxbma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 38775597
For the lists, just write the size of the list first, and then all the items. Same with the dictionary entries. If you know there won't be any '\n' characters in a string then that would be a good way to separate strings.
The binary data is easy. Just open the file in binary write mode and write it. Your entity fields may be good to write out in binary as well.
0
 
LVL 3

Accepted Solution

by:
contactnaeem earned 500 total points
ID: 38776416
Think through your structure, then design a schema for type of your structure , for each class / collection write save and load methods to populate objects from xml using xml reader and writer. I think that will be efficient and clean way. i.e In your structure you can pass an xml to your top most class and it will pass the reader in hierarchy to the bottom so objects will get populated, simlarly while saving you will call save method of your top most class which will save whole structure. Create Interfaces and abstract classes for common logic. This will be alot more extenedable structure for future enhancements.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Progress

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question