Files
SabreTools.Serialization/Files/Hashfile.Serializer.cs

35 lines
1.0 KiB
C#
Raw Permalink Normal View History

2023-09-09 00:02:56 -04:00
namespace SabreTools.Serialization.Files
{
public partial class Hashfile : IFileSerializer<Models.Hashfile.Hashfile>
{
/// <inheritdoc/>
#if NET48
2023-09-11 01:23:29 -04:00
public bool Serialize(Models.Hashfile.Hashfile obj, string path) => Serialize(obj, path, Hash.CRC);
2023-09-09 00:02:56 -04:00
#else
2023-09-11 01:23:29 -04:00
public bool Serialize(Models.Hashfile.Hashfile? obj, string? path) => Serialize(obj, path, Hash.CRC);
#endif
/// <inheritdoc/>
#if NET48
public bool Serialize(Models.Hashfile.Hashfile obj, string path, Hash hash)
#else
public bool Serialize(Models.Hashfile.Hashfile? obj, string? path, Hash hash)
2023-09-09 00:02:56 -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.Hashfile().Serialize(obj, hash))
2023-09-09 00:02:56 -04:00
{
if (stream == null)
return false;
using (var fs = System.IO.File.OpenWrite(path))
{
stream.CopyTo(fs);
return true;
}
}
}
}
}