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

  • Home
  • SEARCH
  • 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 6931833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:37:43+00:00 2026-05-27T11:37:43+00:00

I search for a serializable dictionary in c# (framework 2.0), and I found this

  • 0

I search for a serializable dictionary in c# (framework 2.0), and I found this one :

http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx

which is pretty nice but I would like to have it serialize my dictionary like this :

<item>
    <key>my_first_key</key>
    <value>my_first_value</value>
</item>
<item>
    <key>my_second_key</key>
    <value>my_second_value</value>
</item>

I tried to modify the writeXml method like this :

writer.WriteStartElement("item")
writer.WriteElementString("key", key.ToString)   
writer.WriteElementString("value", value.ToString)  

And it works fine, but to deserialize the xml input as a dictionary, i don’t manage to make it work. I tried this :

reader.ReadStartElement("item")

reader.ReadStartElement("key")
Dim key As String = reader.ReadString()

And i get the key correctly, but into a String object. And when i try to add my key/value pair like this :

Me.Add(key, value)

It doesn’t work since key is a string and not a TKey type. Do you know how to “cast” or convert a string into a TKey ? Or encapsulate the key/value as a string into a TKey/Tvalue type ?

Thanks a lot in advance!

  • 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-27T11:37:43+00:00Added an answer on May 27, 2026 at 11:37 am

    Your requirement seems to focus very much on string, while the code as proposed is generic. However, you can probably special case this, i.e.

    reader.ReadStartElement("key");
    if(typeof(TKey) == typeof(string)) {
        TKey key = (TKey)(object)reader.ReadString();
    } else {           
        TKey key = (TKey)keySerializer.Deserialize(reader);
    }
    reader.ReadEndElement();
    

    (and likewise for the value)

    and:

    writer.WriteStartElement("item")
    if(typeof(TKey) == typeof(string)) {
        writer.WriteElementString("key", (string)(object)key);
    } else {
        writer.WriteStartElement("key");
        keySerializer.Serialize(writer, key);
        writer.WriteEndElement();
    }
    

    (and similar for the value)

    Untested – but should do the job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I search didSelectRowAtIndexPath this key word And found most problem is how to trigger
I search on internet but did not find any best solution, i found one
I search a good calendar for my business application. The Microsoft ASP.NET calendar is
Search the web for the phrase I cosay. I run across this phrase being
I search for nurple in a file. I found it, great. But now, every
i search a good tutorial to learn how to use entity framework in the
Search logic is automagically doing an INNER JOIN on one the tables in my
i search for links from a website with this code. <?php $ch = curl_init();
I search for a long time, but I still not found the answer. In
I had created a framework for a project in the past that one of

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.