Skip to content

Instantly share code, notes, and snippets.

@lindexi
Created November 24, 2016 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindexi/abd158695f4e1fc8a543f793e9e7bf5a to your computer and use it in GitHub Desktop.
Save lindexi/abd158695f4e1fc8a543f793e9e7bf5a to your computer and use it in GitHub Desktop.
/// <summary>
/// Uses the local list of accounts and returns an XML formatted string representing the list
/// </summary>
/// <returns>XML formatted list of accounts</returns>
public static string SerializeAccountListToXml()
{
XmlSerializer xmlizer = new XmlSerializer(typeof(List<Account>));
StringWriter writer = new StringWriter();
xmlizer.Serialize(writer, AccountList);
return writer.ToString();
}
/// <summary>
/// Takes an XML formatted string representing a list of accounts and returns a list object of accounts
/// </summary>
/// <param name="listAsXml">XML formatted list of accounts</param>
/// <returns>List object of accounts</returns>
public static List<Account> DeserializeXmlToAccountList(string listAsXml)
{
XmlSerializer xmlizer = new XmlSerializer(typeof(List<Account>));
TextReader textreader = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(listAsXml)));
return AccountList = (xmlizer.Deserialize(textreader)) as List<Account>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment