Created
July 1, 2014 03:49
-
-
Save AlexArchive/8637144ff28080a4efa0 to your computer and use it in GitHub Desktop.
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
public static class Serializer | |
{ | |
public static string Serialize(object graph) | |
{ | |
var document = new XDocument(); | |
var type = graph.GetType(); | |
document.Add(new XElement(type.Name)); | |
var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty); | |
foreach (var property in properties) | |
{ | |
var propertyValue = property.GetValue(graph); | |
var propertyElement = new XElement(property.Name); | |
propertyElement.Value = propertyValue.ToString(); | |
document.Root.Add(propertyElement); | |
} | |
return document.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment