Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-01-22
3
Medium Priority
?
675 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 30

Accepted Solution

by:
anarki_jimbel earned 2000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses

877 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