Skip to content

Instantly share code, notes, and snippets.

@AlexArchive
Created July 1, 2014 03:49
Show Gist options
  • Save AlexArchive/8637144ff28080a4efa0 to your computer and use it in GitHub Desktop.
Save AlexArchive/8637144ff28080a4efa0 to your computer and use it in GitHub Desktop.
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