Skip to content

Instantly share code, notes, and snippets.

@margusmartsepp
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save margusmartsepp/2df6724bf6134af40fc4 to your computer and use it in GitHub Desktop.

Select an option

Save margusmartsepp/2df6724bf6134af40fc4 to your computer and use it in GitHub Desktop.
c# Serialize
public static bool Serialize<T>(this T item, string filename)
{
try
{
var ser3 = new XmlSerializer(typeof(T));
using (var writer = XmlWriter.Create(filename))
{
ser3.Serialize(writer, item);
}
return true;
}
catch (Exception ex)
{
return false;
}
}
@margusmartsepp
Copy link
Copy Markdown
Author

Class to be serialized should be with Public access modifier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment