public static string SerializeObjectIndentedTo use it, just pass in your object and get an xml back!(T dataContract, bool omitXmlDeclaration = false) where T : class { using (var output = new StringWriter()) { using (var writer = new XmlTextWriter(output) { Formatting = Formatting.Indented }) { if (!omitXmlDeclaration) writer.WriteStartDocument(); var serializer = new System.Runtime.Serialization.DataContractSerializer(typeof(T)); serializer.WriteObject(writer, dataContract); return output.GetStringBuilder().ToString(); } } }
Saturday, 23 February 2019
Serializing a data contract with xml declaration and indented formatting
This code will serialize your object graph and also do xml indentation and adding an xml declaration at the top, using DataContractSerializer.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment