Created
July 7, 2023 19:49
-
-
Save IJsWorkshop/e5b7268f86b76a743b9f290be704d80d to your computer and use it in GitHub Desktop.
Basic custom generic Serializer to add your data to a file
This file contains hidden or 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 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