How ardalis/smartenum works
Project Type & Purpose
• The project is a library (with multiple NuGet packages) that provides “Smart Enum” functionality.
• The README and file structure show that while the core functionality is provided in the “src/SmartEnum” directory, the project is extended via several integration packages (e.g., SmartEnum.Dapper, SmartEnum.EFCore, SmartEnum.JsonNet, etc.), each targeting specific external frameworks or concerns.
File Structure
• Top-Level Components:
• Root files (e.g., .editorconfig, .gitignore, LICENSE, README.md, and solution file [SmartEnum.sln]).
• GitHub workflows and CI configurations for building, testing, and publishing.
• Core Code:
• Located in the “src” folder, which is subdivided into:
▪ “SmartEnum” – the main library providing the enums implementation.
▪ Subdirectories for integration libraries (e.g., SmartEnum.AutoFixture, SmartEnum.Dapper, SmartEnum.EFCore, SmartEnum.GuardClauses, SmartEnum.JsonNet, SmartEnum.MessagePack, SmartEnum.ModelBinding, SmartEnum.ProtoBufNet, SmartEnum.SystemTextJson, SmartEnum.Utf8Json).
• Additional Supporting Components:
• Tests: Organized under “test” (unit tests and integration tests for each integration package).
• Benchmarks: Found under “benchmarks”, used to measure performance.
• Build and packaging configuration files (Directory.Build.props, Directory.Packages.props) that tie the solution together.
• Main Components to Include:
• Client Applications (consumers) that will install the NuGet packages.
• The Core “SmartEnum” library, which implements the central type-safe enum logic.
• Integration Libraries/Extensions:
▪ AutoFixture integration – allows AutoFixture to use or generate SmartEnum instances.
▪ Serialization integrations – SmartEnum.JsonNet, SmartEnum.SystemTextJson, SmartEnum.Utf8Json, SmartEnum.MessagePack (each providing converters for their corresponding JSON or binary frameworks).
▪ ORM integrations – SmartEnum.EFCore and SmartEnum.Dapper (with DapperSmartEnum variants) for mapping SmartEnum types to database columns.
▪ Model Binding integration – SmartEnum.ModelBinding to facilitate binding in ASP.NET scenarios.
▪ GuardClause support – SmartEnum.GuardClauses for enforcing valid enum transitions.
• Testing & Benchmarking Infrastructure:
▪ Unit Test projects in the “test” folder, each referencing a particular integration package or the core library.
▪ Benchmark projects in the “benchmarks” folder evaluating performance (e.g., on list, lookup, and switch operations).
• Relationships and Interactions:
• External dependencies (e.g., JSON.Net, System.Text.Json, Dapper, EF Core, AutoFixture) as external systems that interact with the respective integration packages.
Architectural Patterns & Design Principles
• Modular Design: The project is split into many small, focused NuGet packages, each responsible for a single integration or extension.
• Separation of Concerns: The core logic of SmartEnum is isolated from the specific framework adaptations (e.g., serialization converters for JSON frameworks, or type handlers for Dapper).
• Extensibility: The design supports extension via inheritance (e.g., DapperSmartEnum, SmartFlagEnum variants) and composition.
• Integration Testing & Performance Tuning: Use of dedicated test and benchmark projects helps ensure correctness and performance.
• Clear labels on all components (e.g., “SmartEnum (Core)”, “SmartEnum.Dapper”, “SmartEnum.EFCore”, “Tests”, “Benchmarks”).
• Dependency/invocation (e.g., integration components rely on the core library).
• Data flow (e.g., from client application to ORM layer through the SmartEnum converter).
• Core modules (central block).
• Integration packages (periphery blocks targeting specific external frameworks).
• Supporting projects (tests and benchmarks).
• External dependencies (third-party libraries like AutoFixture, JSON.Net, EF Core, etc.).