Files
SabreTools.Serialization/Files/SeparatedValue.Serializer.cs

38 lines
1.1 KiB
C#
Raw Permalink Normal View History

2023-09-09 01:41:49 -04:00
using SabreTools.Models.SeparatedValue;
using SabreTools.Serialization.Interfaces;
2023-09-09 01:41:49 -04:00
namespace SabreTools.Serialization.Files
{
public partial class SeparatedValue : IFileSerializer<MetadataFile>
{
/// <inheritdoc/>
#if NET48
2023-09-11 01:23:29 -04:00
public bool Serialize(MetadataFile obj, string path) => Serialize(obj, path, ',');
2023-09-09 01:41:49 -04:00
#else
2023-09-11 01:23:29 -04:00
public bool Serialize(MetadataFile? obj, string? path) => Serialize(obj, path, ',');
#endif
/// <inheritdoc/>
#if NET48
public bool Serialize(MetadataFile obj, string path, char delim)
#else
public bool Serialize(MetadataFile? obj, string? path, char delim)
2023-09-09 01:41:49 -04:00
#endif
{
2023-09-10 17:32:03 -04:00
if (string.IsNullOrWhiteSpace(path))
return false;
2023-09-11 01:23:29 -04:00
using (var stream = new Streams.SeparatedValue().Serialize(obj, delim))
2023-09-09 01:41:49 -04:00
{
if (stream == null)
return false;
using (var fs = System.IO.File.OpenWrite(path))
{
stream.CopyTo(fs);
return true;
}
}
}
}
}