using System.IO;
using SabreTools.Serialization.Interfaces;
namespace SabreTools.Serialization.Files
{
///
/// Base class for other XML serializers
///
///
public partial class XmlFile : IFileSerializer
{
///
public bool Serialize(T? obj, string? path)
=> 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
public bool Serialize(T? obj, string? path, string? name = null, string? pubid = null, string? sysid = null, string? subset = null)
{
if (string.IsNullOrEmpty(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;
}
}
}