Page 1 of 1

Saving Collections containing Collections

Posted: Thu Jan 29, 2015 10:05 am
by Joel
Saving Collections of Collections
Easy Save cannot currently saving Collections containing Collections natively. However, there's a very easy workaround using Tags.

Here's an example using a List of List<int>:

To save the List of List<int> ...
// Create the List of Lists which we want to save.
List< List<int> > outerList = CreateListOfLists();

// Save the length of the List.
ES2.Save( outerList.Count, "myFile.txt?tag=outerListCount" );
// Save each inner List, appending it's position to it's tag.
for(int i=0; i<outerList.Count; i++)
    ES2.Save( outerList, "myFile.txt?tag=innerList"+i );

And then to Load the List of List<int> ...
// Reset our List.
outerList = new List< List<int> >();

// Get the length of the outer list.
int outerListCount = ES2.Load<int>( "myFile.txt?tag=outerListCount" );
// Now load the inner lists in a similar way to how we saved them.
for(int i=0; i<outerListCount; i++)
    outerList.Add( ES2.LoadList<int>( "myFile.txt?tag=innerList"+i ) );