public static T Deserialize<T, S>(S stream) where S : Stream where T : class, new() { using (stream) { XmlSerializer xmlSearializer = new XmlSerializer(typeof(T)); // fileStream.Position = 0; // fileStream.Seek(0, SeekOrigin.Begin); return (T)xmlSearializer.Deserialize(stream); } } public static void Serialize<T, S>(T obj, S stream) where S : Stream where T : class, new() { using (stream) { XmlSerializer xmlFormat = new XmlSerializer(typeof(T)); xmlFormat.Serialize(stream, obj); } }