Created
August 23, 2018 10:02
-
-
Save h09shais/411c8bd2fd373cbd619997b63f08c61a to your computer and use it in GitHub Desktop.
C# Model to XML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static string CreateXml(object model) | |
{ | |
var xmlDoc = new XmlDocument(); | |
var xmlSerializer = new XmlSerializer(model.GetType()); | |
using (var xmlStream = new MemoryStream()) | |
{ | |
xmlSerializer.Serialize(xmlStream, model); | |
xmlStream.Position = 0; | |
xmlDoc.Load(xmlStream); | |
return xmlDoc.InnerXml; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var model = ... ; | |
File.WriteAllText("Path, for example ... model.xml", CreateXml(model)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment