7 January, 2011
2 Comments
1 category
If you want to convert a custom object [Product] to a string by using the XmlSerializer class, you can use the StringWriter class like:
StringBuilder result = new StringBuilder(string.Empty); // Get the product from filesystem Product product = Load(); // Convert object to string by using XmlSerializer using (StringWriter writer = new StringWriter(result)) { XmlSerializer xs = new XmlSerializer(typeof(Product)); xs.Serialize(writer, product); }
Tags: C#
Category: Uncategorized
Very elegant solution compared to the other solutions I was finding online. Thanks for posting this. 🙂
short and sweet… finally found what i was looking for. thanks…