Solved

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

Posted on 2013-01-22
3
553 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
ID: 38807602
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
ID: 38808260
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
ID: 38819295
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 Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Winforms Signing 13 33
Help with error in Query 2 31
Unable to connect C# program to an SQL database - Exception occurs. 4 49
Visual Studio npm 1 12
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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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