Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save IJsWorkshop/e5b7268f86b76a743b9f290be704d80d to your computer and use it in GitHub Desktop.
Save IJsWorkshop/e5b7268f86b76a743b9f290be704d80d to your computer and use it in GitHub Desktop.
Basic custom generic Serializer to add your data to a file
public static string Serializer<T>(this T obj)
{
var sb = new StringBuilder();
sb.AppendLine($"<record>");
var props = obj.GetType().GetProperties();
// add values
foreach (var prop in props)
{
sb.AppendLine($"<{prop.Name} type='{prop.PropertyType}'>{prop.GetValue(obj, null)}</{prop.Name}>");
}
sb.AppendLine($"</record>");
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment