using System.IO;
namespace SabreTools.Serialization.Files
{
///
/// Base class for other XML serializers
///
///
public partial class XmlFile : IFileSerializer
{
///
#if NET48
public bool Serialize(T obj, string path)
#else
public bool Serialize(T? obj, string? path)
#endif
=> Serialize(obj, path, null, null, null, null);
///
/// Serializes the defined type to an XML file
///
/// Data to serialize
/// Path to the file to serialize to
/// Data to serialize
/// Optional DOCTYPE name
/// Optional DOCTYPE pubid
/// Optional DOCTYPE sysid
/// Optional DOCTYPE name
/// True on successful serialization, false otherwise
#if NET48
public bool Serialize(T obj, string path, string name = null, string pubid = null, string sysid = null, string subset = null)
#else
public bool Serialize(T? obj, string? path, string? name = null, string? pubid = null, string? sysid = null, string? subset = null)
#endif
{
if (string.IsNullOrWhiteSpace(path))
return false;
using (var stream = new Streams.XmlFile().Serialize(obj, name, pubid, sysid, subset))
{
if (stream == null)
return false;
using (var fs = File.OpenWrite(path))
{
stream.CopyTo(fs);
}
return true;
}
}
}
}