SourceGenerationContext.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Collections.Concurrent;
  2. using System.Text.Json.Serialization;
  3. namespace Terminal.Gui.Configuration;
  4. /// <summary>
  5. /// Allow AOT and self-contained single file applications with the <see cref="System.Text.Json.Serialization"/>.
  6. /// <para>
  7. /// The SourceGenerationContext class leverages the System.Text.Json source generation feature to pre-generate
  8. /// serialization metadata for specific types. This approach avoids runtime reflection, which is problematic in AOT
  9. /// scenarios where metadata might be stripped, and improves performance by generating serialization code at
  10. /// compile time.
  11. /// </para>
  12. /// </summary>
  13. [JsonSerializable (typeof (bool?))]
  14. [JsonSerializable (typeof (Dictionary<string, object>))]
  15. [JsonSerializable (typeof (List<string>))]
  16. [JsonSerializable (typeof (Attribute))]
  17. [JsonSerializable (typeof (Color))]
  18. [JsonSerializable (typeof (Key))]
  19. [JsonSerializable (typeof (Glyphs))]
  20. [JsonSerializable (typeof (Alignment))]
  21. [JsonSerializable (typeof (AlignmentModes))]
  22. [JsonSerializable (typeof (LineStyle))]
  23. [JsonSerializable (typeof (ShadowStyle))]
  24. [JsonSerializable (typeof (MouseState))]
  25. [JsonSerializable (typeof (TextStyle))]
  26. [JsonSerializable (typeof (Dictionary<ColorName16, string>))]
  27. [JsonSerializable (typeof (Dictionary<string, Color>))]
  28. [JsonSerializable (typeof (Dictionary<string, ConfigProperty>))]
  29. [JsonSerializable (typeof (ConcurrentDictionary<string, ConfigProperty>))]
  30. [JsonSerializable (typeof (ConfigProperty))]
  31. [JsonSerializable (typeof (Scope<string>))]
  32. [JsonSerializable (typeof (AppSettingsScope))]
  33. [JsonSerializable (typeof (SettingsScope))]
  34. [JsonSerializable (typeof (ConcurrentDictionary<string, ThemeScope>))]
  35. [JsonSerializable (typeof (Dictionary<string, Scheme>))]
  36. internal partial class SourceGenerationContext : JsonSerializerContext
  37. { }