Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 890683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:46:20+00:00 2026-05-15T13:46:20+00:00

This is my class structure: class DataItem { public string Id { get; set;

  • 0

This is my class structure:

class DataItem
{
   public string Id { get; set; }
   public string Type { get; set; }

   private Dictionary<string, DataProperty> properties = new Dictionary<string, DataProperty>();

   public Dictionary<string, DataProperty> Properties
   {
       get { return properties; }
       set { properties = value; }
   }
}

public class DataProperty
{    
      public string Key { get; set; }
      public string Value { get; set; }
      public bool Required { get; set; }
}

This is XML I want to use (NOTE: I can change the xml if needed):

<Data>
  <DataItem>
    <id>ph15</id>
    <type>core</type>
    <properties>
      <DataProperty>
        <key>size</key>
        <value>50%</value>
        <required>false</required>
      </DataProperty>
      <DataProperty>
        <key>color</key>
        <value>red</value>
        <required>true</required>
      </DataProperty>
    </properties>
  </DataItem>
  <DataItem>
    <id>ph234</id>
    <type>core</type>
    <properties>
    </properties>
  </DataItem>
</Data>

Eventually XML should be loaded into another dictionary:

private Dictionary<string, DataItem> Mydata;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:46:21+00:00Added an answer on May 15, 2026 at 1:46 pm

    Unfortunately, generic dictionaries are not xml serializable.

    The workaround is to greate a separate field specifically to support serialization that exposes the elements of the dictionary as a list of key/value pairs. You then also have to mark the dictionary member with the XmlIgnore attribute.

    Alternatively, you can use something other than XmlSerializer (like DataContractSerializer) which does support dictionary types.

    Here’s a link to an article which provides a good example of how modify your type to support XML Serialization with a dictionary.

    One important point if you use this code – the serialized items may appear in arbitrary order in the output. This is a consequence of using dictinoaries (which are unordered) as the storage model for your data.

    [XmlIgnore()]   
    public Dictionary<string, DataProperty> Properties
    {   
        set { properties = value; }   
        get { return properties ; }   
    }
    
    
    [XmlArray("Stuff")]   
    [XmlArrayItem("StuffLine", Type=typeof(DictionaryEntry))]   
    public DictionaryEntry[] PropertiesList
    {   
        get  
        {   
            //Make an array of DictionaryEntries to return   
            DictionaryEntry[] ret=new DictionaryEntry[Properties.Count];   
            int i=0;   
            DictionaryEntry de;   
            //Iterate through Stuff to load items into the array.   
            foreach (KeyValuePair<string, DataProperty> props in Properties)   
            {   
                de = new DictionaryEntry();   
                de.Key = props.Key;   
                de.Value = props.Value;   
                ret[i]=de;   
                i++;   
            }   
            return ret;   
        }   
        set  
        {   
            Properties.Clear();   
            for (int i=0; i<value.Length; i++)   
            {   
                Properties.Add((string)value[i].Key, (DataProperty)value[i].Value);   
            }   
        }   
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 classes with this structure: class ClassA { String typeA; List<String> valuesA;
I have a structure similar to this: class OuterClass{ AnimatorListener sth; public OuterClass(){ sth
I have this structure of classes: public class L3Message { public int Number {
I have classes structured like this: Public MustInherit Class A ' several properties End
Can someone tell me if this class structure is bad? class abstract Parent{ public
I have this class structure: List<myObject> myList = new List<myObject>(); myObject { List<myOtherObject> myOtherList
I have an Class structure like this: class A { Dictionary<UInt64, B> listB; method1(){}
I have a class structure that looks like this: class Person { public virtual
I have a class structure like this: class A { public someFunction() { $objectB
I have a class structure like this public class Entity { public int Id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.