2010-04-04 00:12:01 +00:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace Jellyfish.Library
|
|
|
|
|
{
|
|
|
|
|
public static class XmlSerializerHelpers
|
|
|
|
|
{
|
|
|
|
|
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
|
2010-06-06 21:48:51 +00:00
|
|
|
|
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
|
2010-05-28 10:48:08 +00:00
|
|
|
|
public static T Deserialize<T>(Stream stream, string defaultNamespace = null)
|
2010-04-04 00:12:01 +00:00
|
|
|
|
{
|
|
|
|
|
using (var reader = XmlReader.Create(stream))
|
|
|
|
|
{
|
|
|
|
|
var serializer = new XmlSerializer(typeof(T), defaultNamespace);
|
|
|
|
|
return (T)serializer.Deserialize(reader);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-06 21:48:51 +00:00
|
|
|
|
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
|
2010-05-28 10:48:08 +00:00
|
|
|
|
public static void Serialize<T>(Stream stream, T instance, string defaultNamespace = null)
|
2010-04-04 00:12:01 +00:00
|
|
|
|
{
|
|
|
|
|
using (var writer = XmlWriter.Create(stream))
|
|
|
|
|
{
|
|
|
|
|
var serializer = new XmlSerializer(typeof(T), defaultNamespace);
|
|
|
|
|
serializer.Serialize(writer, instance);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|