Recent updates to NetEscapades.EnumGenerators: new APIs and System.Memory support The article summarizes updates to version 1.0.0-beta19 of the NetEscapades.EnumGenerators NuGet package, a source generator that creates fast methods for working with enums by replacing slow built-in operations like `ToString()` with optimized switch statements. New features include the ability to disable number parsing in `Parse()` and `TryParse()` methods, support for automatically applying `ToLowerInvariant()` or `ToUpperInvariant()` to serialized enums, and added `ReadOnlySpan` API support when using the System.Memory package. In this post I describe some of the recent updates added in version 1.0.0-beta19 of my source generator NuGet package NetEscapades.EnumGenerators https://github.com/andrewlock/NetEscapades.EnumGenerators which you can use to add fast methods for working with enum s. I start by briefly describing why the package exists and what you can use it for, then I walk through some of the changes in the latest release. Why should you use an enum source generator? why-should-you-use-an-enum-source-generator- NetEscapades.EnumGenerators https://github.com/andrewlock/NetEscapades.EnumGenerators provides a source generator that is designed to work around an annoying characteristic of working with enums: some operations are surprisingly slow. As an example, let's say you have the following enum: public enum Colour { Red = 0, Blue = 1, } At some point, you want to print the name of a Color variable, so you create this helper method: public void PrintColour Colour colour { Console.WriteLine "You chose "+ colour.ToString ; // You chose Red } While this looks like it should be fast, it's really not. NetEscapades.EnumGenerators works by automatically generating an implementation that is fast. It generates a ToStringFast method that looks something like this: public static class ColourExtensions { public string ToStringFast this Colour colour = colour switch { Colour.Red = nameof Colour.Red , Colour.Blue = nameof Colour.Blue , = colour.ToString , } } } This simple switch statement checks for each of the known values of Colour and uses nameof to return the textual representation of the enum . If it's an unknown value, then it falls back to the built-in ToString implementation for simplicity of handling of unknown values for example this is valid C : PrintColour Colour 123 . If we compare these two implementations using BenchmarkDotNet https://benchmarkdotnet.org/ for a known colour, you can see how much faster the ToStringFast implementation is, even in .NET 10 | Method | Mean | Error | StdDev | Median | Gen0 | Allocated | |---|---|---|---|---|---|---| | ToString | 6.4389 ns | 0.1038 ns | 0.0971 ns | 6.4567 ns | 0.0038 | 24 B | | ToStringFast | 0.0050 ns | 0.0202 ns | 0.0189 ns | 0.0000 ns | - | - | Obviously your mileage may vary and the results will depend on the specific enum and which of the generated methods you're using, but in general, using the source generator should give you a free performance boost If you want to learn more about all the features the package provides, check my previous blog posts or see the project README . That's the basics of why I think you should take a look at the source generator. Now let's take a look at the latest features added. Updates in 1.0.0-beta19 updates-in-1-0-0-beta19 Version 1.0.0-beta19 of NetEscapades.EnumGenerators https://www.nuget.org/packages/NetEscapades.EnumGenerators/ was released to nuget.org recently and includes a number of new features. I'll describe each of the updates in more detail below, covering the following: - Support for disabling number parsing. - Support for automatically calling ToLowerInvariant or ToUpperInvariant on the serialized enum. - Add support for ReadOnlySpan