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
  1. Home
  2. General Programming
  3. C#
  4. Serialization for an ArrayList

Serialization for an ArrayList

Scheduled Pinned Locked Moved C#
xmljsonquestion
3 Posts 2 Posters 0 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.
  • Z Offline
    Z Offline
    zecodela
    wrote on last edited by
    #1

    hi, i got several settings objects stored in a ArrayList. i can do the simply single object serialization. but, any method to serialize the whole ArrayList to a xml file? thanks, jim

    R 1 Reply Last reply
    0
    • Z zecodela

      hi, i got several settings objects stored in a ArrayList. i can do the simply single object serialization. but, any method to serialize the whole ArrayList to a xml file? thanks, jim

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      Have you tried to just serialize the whole ArrayList alltogether? An ArrayList is an object like any other. If I remember right it is even serializable. So if all contained classes are serializable it should work with a single function call. Other solution would be to copy your objects (from the ArrayList) into an object array (object[]) and serialize it.

      Z 1 Reply Last reply
      0
      • R Robert Rohde

        Have you tried to just serialize the whole ArrayList alltogether? An ArrayList is an object like any other. If I remember right it is even serializable. So if all contained classes are serializable it should work with a single function call. Other solution would be to copy your objects (from the ArrayList) into an object array (object[]) and serialize it.

        Z Offline
        Z Offline
        zecodela
        wrote on last edited by
        #3

        yes, the current method i used is the copy the arraylist to a object array like below code but it need extra work private ArrayList listTradePattern; public class TradePatternList { public TradePatternList() { listTradePattern = new ArrayList(); } [XmlElement("Pattern")] public TradePattern[] TradePatterns { get { TradePattern[] tradepatterns = new TradePattern[ listTradePattern.Count ]; listTradePattern.CopyTo( tradepatterns ); return tradepatterns; } set { if( value == null ) return; TradePattern[] tradepatterns = (TradePattern[])value; listTradePattern.Clear(); foreach( TradePattern tradepattern in tradepatterns ) listTradePattern.Add( tradepattern ); } } }

        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