mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-27 08:39:47 +00:00
* Add JSON/catalog.js logic * Proper json deserialize * Update packages * Catalog is UTF-16 LE, make BaseJsonFile encoding independent * Bump version, use ST.Models 1.4.1 * Implement JsonFile as interface with UTF8 as default * typo
32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
using System.Text;
|
|
using SabreTools.Serialization.Interfaces;
|
|
|
|
namespace SabreTools.Serialization.Files
|
|
{
|
|
/// <summary>
|
|
/// Base class for other JSON serializers
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
public partial class JsonFile<T> : IFileSerializer<T>
|
|
{
|
|
/// <inheritdoc/>
|
|
public T? Deserialize(string? path)
|
|
=> Deserialize(path, new UTF8Encoding(false));
|
|
|
|
/// <summary>
|
|
/// Deserialize a file into <typeparamref name="T"/>
|
|
/// </summary>
|
|
/// <typeparam name="T">Type of object to deserialize to</typeparam>
|
|
/// <param name="path">Path to deserialize from</param>
|
|
/// <param name="encoding">Encoding to parse text as</param>
|
|
/// <returns>Filled object on success, null on error</returns>
|
|
public T? Deserialize(string? path, Encoding encoding)
|
|
{
|
|
using (var data = PathProcessor.OpenStream(path))
|
|
{
|
|
return new Streams.JsonFile<T>().Deserialize(data, encoding);
|
|
}
|
|
}
|
|
}
|
|
}
|