Serialization for an ArrayList
-
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
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.
-
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.
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 ); } } }