Saving Collections containing Collections

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
User avatar
Moodkie Staff
Posts: 3377
Joined: Wed Nov 07, 2012 10:32 pm

Saving Collections containing Collections

Post 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 ) );