No more then a few paragraphs of things I want to archive (instead of try to remember)

Monday, September 19, 2011

Serializing an object to file

I'm always trying to compare two objects of the same type with different situations. An easy way to do this is to kick out the serialized version of each object and diff them with Araxis (or your diffing tool of choice). However, I always forget the snippet used to do this. Keep in mind, you have to have your object decorated with Serializable to do this.

vm = GetViewModel(Client, groupProposal, gpgDashboard);
 
/* start serialization */
var serializer = new XmlSerializer(typeof(GroupProposalGridViewModel));
var output = new StringWriter(new System.Text.StringBuilder());
var xmlTempDocument = new XmlDocument();
 
serializer.Serialize(output,vm);
xmlTempDocument.LoadXml(output.ToString());
xmlTempDocument.Save(@"C:\Temp\GroupProposal.xml");
/* end serialization */
 

0 comments: