This is an example of Serialize funcion that use a object as a parameter (you could pass your own class).
public string Serialize(Object process)
{
MemoryStream stream = null;
TextWriter writer = null;
try
{
stream = new MemoryStream();
writer = new StreamWriter(stream, Encoding.Unicode);
XmlSerializer serializer = new XmlSerializer(process.GetType());
serializer.Serialize(writer, process);
int count = (int)stream.Length;
byte[] arr = new byte[count];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(arr, 0, count);
UnicodeEncoding utf = new UnicodeEncoding();
return utf.GetString(arr).Trim();
}
catch (Exception ex)
{
return string.Empty;
}
finally
{
if (stream != null) stream.Close();
if (writer != null) writer.Close();
}
}