• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 703
  • Last Modified:

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

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
jxbma
Asked:
jxbma
1 Solution
 
sognoctCommented:
check if this library can help you :
http://www.sharpserializer.com/en/index.html
0
 
anarki_jimbelCommented:
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
 
jxbmaSoftware ConsultantAuthor Commented:
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

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now