mirror of
https://github.com/digital-jellyfish/Virtu.git
synced 2024-11-27 00:49:39 +00:00
365e5723c1
--HG-- extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4050811
32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
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")]
|
|
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
|
|
public static T Deserialize<T>(Stream stream, string defaultNamespace = null)
|
|
{
|
|
using (var reader = XmlReader.Create(stream))
|
|
{
|
|
var serializer = new XmlSerializer(typeof(T), defaultNamespace);
|
|
return (T)serializer.Deserialize(reader);
|
|
}
|
|
}
|
|
|
|
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
|
|
public static void Serialize<T>(Stream stream, T instance, string defaultNamespace = null)
|
|
{
|
|
using (var writer = XmlWriter.Create(stream))
|
|
{
|
|
var serializer = new XmlSerializer(typeof(T), defaultNamespace);
|
|
serializer.Serialize(writer, instance);
|
|
}
|
|
}
|
|
}
|
|
}
|