-
Notifications
You must be signed in to change notification settings - Fork 30
Add C#14 extension members #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add C#14 extension members #148
Conversation
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds support for C# 14 extension members to the EntityFrameworkCore.Projectables source generator. Extension members are a new C# 14 feature that allow defining members within an extension() block, providing a more natural syntax for extending types compared to traditional extension methods.
Changes:
- Updated Microsoft.CodeAnalysis.CSharp to version 5.0.0 to support C# 14 features
- Modified the source generator to detect and process extension members using the
IsExtensionproperty - Added logic to rewrite extension parameter references (e.g.,
e) to@thisin generated expressions - Added comprehensive test coverage including generator tests and functional tests for extension member properties, methods, and methods with parameters
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Directory.Packages.props | Updated Microsoft.CodeAnalysis.CSharp from 4.11.0 to 5.0.0 |
| Directory.Build.props | Added conditional LangVersion 14.0 for net10.0 target framework |
| ProjectableInterpreter.cs | Added extension member detection and handling logic with helper methods |
| ExpressionSyntaxRewriter.cs | Added extension parameter name tracking and identifier replacement |
| ProjectionExpressionGeneratorTests.cs | Added 5 generator tests for extension member scenarios (NET10_0_OR_GREATER) |
| ExtensionMemberTests.cs | Added 2 functional tests for extension member methods |
| EntityExtensions.cs | Added extension member definitions for Entity and int types |
| Entity.cs | Added Entity class for extension member testing |
| Various .verified.txt files | Expected output verification files for all new tests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| static IEnumerable<string> GetNestedInClassPathForExtensionMember(ITypeSymbol extensionType) | ||
| { | ||
| // For extension members, the ContainingType is the extension block, | ||
| // and its ContainingType is the outer class (e.g., EntityExtensions) | ||
| var outerType = extensionType.ContainingType; | ||
|
|
||
| if (outerType is not null) | ||
| { | ||
| return GetNestedInClassPath(outerType); | ||
| } | ||
|
|
||
| return []; | ||
| } |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation comment describes the method's purpose well, but should be a proper XML documentation comment using /// instead of // to match the project's documentation style and provide IntelliSense support.
| // Handle C# 14 extension parameter replacement (e.g., `e` in `extension(Entity e)` becomes `@this`) | ||
| if (_extensionParameterName is not null && node.Identifier.Text == _extensionParameterName) | ||
| { | ||
| var symbol = _semanticModel.GetSymbolInfo(node).Symbol; | ||
|
|
||
| // Check if this identifier refers to the extension parameter | ||
| if (symbol is IParameterSymbol { ContainingSymbol: INamedTypeSymbol { IsExtension: true } }) | ||
| { | ||
| return SyntaxFactory.IdentifierName("@this") | ||
| .WithLeadingTrivia(node.GetLeadingTrivia()) | ||
| .WithTrailingTrivia(node.GetTrailingTrivia()); | ||
| } | ||
| } |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the inline comment is helpful, consider adding XML documentation to the VisitIdentifierName method explaining that it now handles extension parameter replacement in addition to its other responsibilities. This would improve maintainability and help future developers understand the method's full scope.
Fixes #141