Templates

This commit is contained in:
2026-01-26 10:24:16 -06:00
parent 5bde8db8cf
commit 523cd2104f
6 changed files with 181 additions and 62 deletions

View File

@@ -17,7 +17,7 @@ public class SzParser
}
catch (JsonException e)
{
throw new Exception("Parse Error: " + e.Message);
throw new Exception("Dataset Serialization Error: " + e.Message);
}
}
@@ -34,5 +34,33 @@ public class SzParser
return null;
}
}
public string SerializeTemplateToJson(ISzTemplate template)
{
try
{
var templateType = template.GetType();
var jsonString = JsonSerializer.Serialize(template, templateType, _jsonOptions);
return jsonString;
}
catch (Exception e)
{
throw new Exception("Template Serialization Error: " + e.Message);
}
}
public T? DeserializeTemplate<T>(string jsonString)
{
try
{
var result = JsonSerializer.Deserialize<T>(jsonString, _jsonOptions);
return result;
}
catch (Exception e)
{
SZ.Logger.LogError($"Could not deserialize JSON to type {typeof(T)}: " + e.Message);
return default;
}
}
}