TelegramBot/EnumSerializer.Generator/README.md
2026-08-03 22:52:44 +02:00

939 B

Enum Converter Generator

Background

Telegram.Bot library relies on Json.NET converters to map JSON input to various enums and vice versa.

It's rather tedious and repeating task. So that's where C# source generators come to help.

EnumSerializer.Generator looks for enums annotated with [JsonConverter(typeof(TEnumConverter))] attribute and generates a converter that handles all possible enum values for us.

Credits

This project is heavily inspired by the series of posts by Andrew Lock Creating an incremental generator and NetEscapades.EnumGenerators project.

We use Alexandre Mutel's Scriban templating engine to generate converter class output.