Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. serialization

serialization

Scheduled Pinned Locked Moved C#
data-structuresjsonquestion
3 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    brain2cpu
    wrote on last edited by
    #1

    I want to serialize a private field of a class: ... private ArrayList items = null; ... XmlSerializer serializer = new XmlSerializer(typeof(MyClass)); TextWriter writer = new StreamWriter(path); serializer.Serialize(writer, this); writer.Close(); the items array is serialized only if change it to public, but I do not want to do this. items are presented by the class through some properties, each making some work before returns something; the basic form of items should not be visible. Any solution?

    T 1 Reply Last reply
    0
    • B brain2cpu

      I want to serialize a private field of a class: ... private ArrayList items = null; ... XmlSerializer serializer = new XmlSerializer(typeof(MyClass)); TextWriter writer = new StreamWriter(path); serializer.Serialize(writer, this); writer.Close(); the items array is serialized only if change it to public, but I do not want to do this. items are presented by the class through some properties, each making some work before returns something; the basic form of items should not be visible. Any solution?

      T Offline
      T Offline
      turbochimp
      wrote on last edited by
      #2

      I'm not sure why you're using the XML serializer for this, but here goes... XML serialization is not designed to access private class members. If you want to force XML serialization to store private class mambers, you may be able to do so using the IXmlSerializable interface see here[^] for a little more info. If XML serialization is not a requirement, you might consider binary serialization. There's much better support for customizing the serialization process built into the framework (and documented). Good luck.

      The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

      B 1 Reply Last reply
      0
      • T turbochimp

        I'm not sure why you're using the XML serializer for this, but here goes... XML serialization is not designed to access private class members. If you want to force XML serialization to store private class mambers, you may be able to do so using the IXmlSerializable interface see here[^] for a little more info. If XML serialization is not a requirement, you might consider binary serialization. There's much better support for customizing the serialization process built into the framework (and documented). Good luck.

        The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

        B Offline
        B Offline
        brain2cpu
        wrote on last edited by
        #3

        I choose XML serialization because I need a text file, which can be edited if needed. If other methods give me a text format it would be OK.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups