mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-02-11 13:45:39 +00:00
35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
namespace SabreTools.Serialization.Files
|
|
{
|
|
public partial class Hashfile : IFileSerializer<Models.Hashfile.Hashfile>
|
|
{
|
|
/// <inheritdoc/>
|
|
#if NET48
|
|
public bool Serialize(Models.Hashfile.Hashfile obj, string path) => Serialize(obj, path, Hash.CRC);
|
|
#else
|
|
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)
|
|
#endif
|
|
{
|
|
if (string.IsNullOrWhiteSpace(path))
|
|
return false;
|
|
|
|
using (var stream = new Streams.Hashfile().Serialize(obj, hash))
|
|
{
|
|
if (stream == null)
|
|
return false;
|
|
|
|
using (var fs = System.IO.File.OpenWrite(path))
|
|
{
|
|
stream.CopyTo(fs);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |