Something went wrong. Try again.
.NET ATProtocol Library - Built for Source Gen
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879// <auto-generated />#nullable enable
using System;using System.Text.Json;using CarpaNet.Models;
namespace CarpaNet.Parsing;
/// <summary>/// Parses Lexicon JSON files into strongly-typed models./// </summary>public static class LexiconParser{ private static readonly JsonSerializerOptions SerializerOptions = new() { PropertyNameCaseInsensitive = false, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true };
/// <summary> /// Parses a Lexicon JSON string into a LexiconDocument. /// </summary> /// <param name="json">The JSON content to parse.</param> /// <returns>The parsed LexiconDocument, or null if parsing fails.</returns> public static LexiconDocument? Parse(string? json) { if (string.IsNullOrWhiteSpace(json)) { return null; }
try { return JsonSerializer.Deserialize<LexiconDocument>(json!, SerializerOptions); } catch (JsonException) { return null; } }
/// <summary> /// Tries to parse a Lexicon JSON string. /// </summary> /// <param name="json">The JSON content to parse.</param> /// <param name="document">The parsed document if successful.</param> /// <param name="error">The error message if parsing fails.</param> /// <returns>True if parsing succeeded, false otherwise.</returns> public static bool TryParse(string? json, out LexiconDocument? document, out string? error) { document = null; error = null;
if (string.IsNullOrWhiteSpace(json)) { error = "Empty or null JSON content"; return false; }
try { document = JsonSerializer.Deserialize<LexiconDocument>(json!, SerializerOptions); if (document == null) { error = "Deserialization returned null"; return false; } return true; } catch (JsonException ex) { error = ex.Message; return false; } }}