39 lines
798 B
C#
39 lines
798 B
C#
using System.Text.Json;
|
|
using SzLib.DataObjects;
|
|
|
|
namespace SzLib;
|
|
|
|
public class SzParser
|
|
{
|
|
public readonly ISzFileManager FileManager;
|
|
|
|
private JsonSerializerOptions _jsonOptions = new()
|
|
{
|
|
WriteIndented = true,
|
|
};
|
|
|
|
public SzParser(ISzFileManager szFileManager)
|
|
{
|
|
FileManager = szFileManager;
|
|
}
|
|
|
|
public (string result, SzParseError error) SerializeDatasetToJson(SzDataset dataset)
|
|
{
|
|
try
|
|
{
|
|
var jsonString = JsonSerializer.Serialize(dataset, _jsonOptions);
|
|
return (jsonString, SzParseError.None);
|
|
}
|
|
catch (JsonException e)
|
|
{
|
|
return ("", SzParseError.CouldNotSerialize);
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum SzParseError
|
|
{
|
|
None,
|
|
CouldNotSerialize,
|
|
GenericError,
|
|
} |