Solved

How do I serialize a Dictionary<String,T> collection using the XMLSerializer in .Net/C#?

Posted on 2013-01-22
3
524 Views
Last Modified: 2013-01-25
Hi:

I'm trying to figure out the best way use the XMLSerializer to serialize a Dictionary<String,T> and a Dictionary<String, <List>> object.

I have a class that has something that resembles the following definition:

 public class TemplateFile
    {
        /// <summary>
        ///
        /// </summary>
        private Dictionary<String, EntityClass> dEntities = new Dictionary<string,EntityClass>();
        public Dictionary<String, EntityClass> Entities
        {
            get { return dEntities; }
            set { dEntities = value; }
        }

        /// <summary>
        ///
        /// </summary>
        public Dictionary<String, List<EntityClass>> ListEntities = new Dictionary<string,List<EntityClass>>();
   }

What is the best way to acheive this?

Thanks,
JohnB
0
Comment
Question by:jxbma
3 Comments
 
LVL 9

Expert Comment

by:sognoct
Comment Utility
check if this library can help you :
http://www.sharpserializer.com/en/index.html
0
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 500 total points
Comment Utility
To my knowledge XMLSerializer does not support Dictionary serialization.

One possible way to solve the problem is in the solution:
http://stackoverflow.com/questions/2911514/why-doesnt-xmlserializer-support-dictionary
0
 
LVL 1

Author Closing Comment

by:jxbma
Comment Utility
That certainly was 1 option.
I basically collapsed the dictionary into a list where each entry contained my dictionary key.
i was then able to serialize what I need to.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now