You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This source generator uses modern Roslynincremental generation techniques:
140
+
This source generator leverages Roslyn's modern incremental generation pipeline for optimal performance and developer experience:
141
141
142
-
-**Incremental Pipeline**: Uses `IIncrementalGenerator` for optimal performance
143
-
-**Efficient Syntax Detection**: Only processes method calls that match registration patterns
144
-
-**Immutable Data Transfer**: Uses C# records for efficient data flow between pipeline stages
145
-
-**Cache-Friendly Design**: Pure transforms and value-based equality for maximum caching benefits
146
-
-**Memory Efficient**: Early filtering and minimal allocations in hot paths
142
+
### Modern Incremental Pipeline
147
143
148
-
The generator targets `netstandard2.0` and leverages PolySharp for modern C# language features while maintaining broad compatibility.
144
+
The generator implements a true four-stage incremental pipeline that provides maximum caching benefits:
145
+
146
+
1.**Stage 1: Syntax Detection** - Efficiently identifies registration method calls (`Register<>()`, `RegisterLazySingleton<>()`, `RegisterConstant<>()`) and transforms them into `RegistrationCall` records
147
+
2.**Stage 2: Semantic Analysis** - Processes each `RegistrationCall` with semantic analysis to create `RegistrationTarget` records containing type information and dependency data
148
+
3.**Stage 3: Collection** - Aggregates all `RegistrationTarget` records into a single `RegistrationGroup` for batch processing
149
+
4.**Stage 4: Code Generation** - Transforms the `RegistrationGroup` into final C# source code using efficient StringBuilder and raw string literals
150
+
151
+
### Performance Optimizations
152
+
153
+
-**Cache-Friendly Design**: Each pipeline stage uses pure transforms and immutable records designed for Roslyn's caching system
154
+
-**Memory Efficient**: Avoids LINQ operations in hot paths, uses StringBuilder for string generation, and minimizes allocations
155
+
-**Early Filtering**: Only processes syntax nodes that match registration patterns, ignoring irrelevant code
156
+
-**Incremental Processing**: Only changed files trigger reprocessing, dramatically improving IDE performance
157
+
-**Value-Based Equality**: Records provide efficient equality comparisons for maximum cache hit rates
158
+
159
+
### Technical Features
160
+
161
+
-**Target Framework**: `netstandard2.0` for broad compatibility
162
+
-**Language Features**: Leverages PolySharp for modern C# language features (records, raw strings, pattern matching)
163
+
-**Code Generation**: Uses raw string literals with interpolation for clean, readable generated code
This architecture provides immediate feedback during editing in Visual Studio 17.10+ and significantly reduces compilation times in large solutions.
167
+
168
+
The generator targets `netstandard2.0` and leverages PolySharp for modern C# language features while maintaining broad compatibility.
169
+
170
+
## Development
171
+
172
+
This project is developed with the assistance of AI tools including GitHub Copilot. All AI-generated code is thoroughly reviewed and tested by human developers to ensure quality, performance, and maintainability.
173
+
174
+
## Acknowledgments
175
+
176
+
With thanks to the following libraries and tools that make this project possible:
177
+
178
+
-**PolySharp** - Provides modern C# language features for older target frameworks
179
+
-**Microsoft.CodeAnalysis** - Powers the Roslyn-based source generation
180
+
-**Splat** - The foundational service location framework this generator supports
0 commit comments