How skarllot/enumutilities works
Project Type and Purpose
• This is a source generator tool for C#. It plugs into the build process by leveraging the Roslyn compiler to auto-generate boilerplate code for enums.
• The README explains that developers use the [EnumGenerator] attribute on their enums so that a set of extension methods and factories (e.g., parsing, validation, JSON conversion) are generated at compile time. There’s also special handling for bit flag enums and support for attributes like [EnumMember], [Description], and [Display].
File Structure
• The top-level directories like src, gen, perf, and tests indicate different aspects of the project:
• src: Contains the core EnumUtilities library. This comprises the attribute definitions and parts that might be required at runtime.
• gen: Contains the Roslyn source generators. Notice that there are different folders, for example, separate versions (Roslyn4_3_1 and Roslyn4_4_0) to support different compiler/version scenarios.
• perf: Contains benchmarks to evaluate performance, demonstrating that efficiency is a design goal.
• tests: Contains integration and unit tests to verify that generated code meets expectations.
• There is also extensive configuration for continuous integration (in the .github folder), build settings (Directory.Build.props, global.json), and other metadata files (LICENSE, README, etc.) that show the project’s commitment to quality and standard practices.
Additional Insights from the README
• The README highlights the three main types of generated code per enum: Extensions, Factories, and Validation classes.
• The documentation lays out examples for both “regular” and “[Flags]” enums, and it explains supported attributes (EnumMember, Display, Description) along with JSON converter generation.
• The README also introduces usage examples indicating how the source generator flows: when a developer marks an enum with [EnumGenerator], the generator intervenes during compilation and produces additional code.
a. Main Components:
• EnumUtilities Core Library: In the src directory, define a block for the library that includes utilities like EnumGeneratorAttribute, parsers, and formatters.
• Roslyn Source Generator: Represent the generator modules housed in the “gen” folder (with separate nodes if necessary for different Roslyn versions). This component consumes enums with specific attributes and outputs generated code.
• Testing & Benchmarking: Include nodes for the integration/unit tests (tests folder) and performance benchmarks (perf folder) to ensure quality and performance.
• CI/CD Systems: Optionally, include a node for GitHub Actions (.github/workflows) that show the build, dependency review, and package creation pipelines.
• Developer or External Code Base: Conceptually indicate how a client project (using the NuGet package) will include the EnumUtilities package and see the generated extensions integrated at compile time.
b. Relationships and Interactions:
• That the Core Library (src) is referenced by both the source generation process and by consuming applications.
• How tests and benchmarks interact with the generated code to verify behavior and performance.
c. Architectural Patterns and Design Principles:
• Separation of Concerns: The project distinctly separates the source generation logic (gen), the core runtime libraries (src), and verification (tests and perf).
• Compile-time Code Generation: Emphasize that code generation is integrated into the build process – an essential design principle here.
• Modularity and Version Support: Acknowledge that the project modularizes support for different Roslyn versions, as seen in the two separate generator folders.
• Extensibility: The design accommodates different attributes ([EnumMember], [Description], [Display]), meaning the generator is built to be extensible.
d. Technologies, Frameworks, and Framework Integration:
• C# with .NET 6 SDK (at minimum), Roslyn compiler for source generation, and use of NuGet packaging.
• GitHub Actions for CI/CD and various configuration files (e.g., dotnet-tools.json) indicating integration with standard .NET development tooling.