|
using System;
using System.IO;
namespace ReflectionStudio.Core.FileManagement
{
/// <summary>
/// Serialize/Deserialize object to file or stream
/// </summary>
public class SerializeHelper
{
/// <summary>
/// Serialize an object to a given file
/// </summary>
/// <param name="filePath"></param>
/// <param name="objToSerialize"></param>
/// <param name="asXML"></param>
/// <returns></returns>
static public bool Serialize(string filePath, object objToSerialize, bool asXML = false)
{
if (asXML)
return XmlHelper.Serialize(filePath, objToSerialize);
else
return BinaryHelper.Serialize(filePath, objToSerialize);
}
/// <summary>
/// Deserialize an object from a given file
/// </summary>
/// <param name="filePath"></param>
/// <param name="objType"></param>
/// <param name="asXML"></param>
/// <returns></returns>
static public object Deserialize(string filePath, Type objType, bool asXML = false)
{
if (asXML)
return XmlHelper.Deserialize(filePath, objType);
else
return BinaryHelper.Deserialize(filePath);
}
/// <summary>
/// Serialize an object to a given stream
/// </summary>
/// <param name="stream"></param>
/// <param name="objToSerialize"></param>
/// <param name="asXML"></param>
/// <returns></returns>
static public bool Serialize(Stream stream, object objToSerialize, bool asXML = false)
{
if (asXML)
return XmlHelper.Serialize(stream, objToSerialize);
else
return BinaryHelper.Serialize(stream, objToSerialize);
}
/// <summary>
/// Deserialize an object from a given stream
/// </summary>
/// <param name="stream"></param>
/// <param name="objType"></param>
/// <param name="asXML"></param>
/// <returns></returns>
static public object Deserialize(Stream stream, Type objType, bool asXML = false)
{
if (asXML)
return XmlHelper.Deserialize(stream, objType);
else
return BinaryHelper.Deserialize(stream);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
WPF and MVVM fan, I practice C # in all its forms from the beginning of the NET Framework without mentioning C ++ / MFC and other software packages such as databases, ASP, WCF, Web & Windows services, Application, and now Core and UWP.
In my wasted hours, I am guilty of having fathered C.B.R. and its cousins C.B.R. for WinRT and UWP on the Windows store.
But apart from that, I am a great handyman ... the house, a rocket stove to heat the jacuzzi and the last one: a wood oven for pizza, bread, and everything that goes inside
https://guillaumewaser.wordpress.com/
https://fouretcompagnie.wordpress.com/