-
Notifications
You must be signed in to change notification settings - Fork 31
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
Open
PhenX
wants to merge
3
commits into
koenbeuk:master
Choose a base branch
from
PhenX:copilot/add-csharp-14-extension-members
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+509
−15
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/EntityFrameworkCore.Projectables.FunctionalTests/ExtensionMembers/Entity.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #if NET10_0_OR_GREATER | ||
| namespace EntityFrameworkCore.Projectables.FunctionalTests.ExtensionMembers | ||
| { | ||
| public class Entity | ||
| { | ||
| public int Id { get; set; } | ||
| public string Name { get; set; } = string.Empty; | ||
| } | ||
| } | ||
| #endif |
40 changes: 40 additions & 0 deletions
40
tests/EntityFrameworkCore.Projectables.FunctionalTests/ExtensionMembers/EntityExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #if NET10_0_OR_GREATER | ||
| namespace EntityFrameworkCore.Projectables.FunctionalTests.ExtensionMembers | ||
| { | ||
| public static class EntityExtensions | ||
| { | ||
| extension(Entity e) | ||
| { | ||
| /// <summary> | ||
| /// Extension member property that doubles the entity's ID. | ||
| /// </summary> | ||
| [Projectable] | ||
| public int DoubleId => e.Id * 2; | ||
|
|
||
| /// <summary> | ||
| /// Extension member method that triples the entity's ID. | ||
| /// </summary> | ||
| [Projectable] | ||
| public int TripleId() => e.Id * 3; | ||
|
|
||
| /// <summary> | ||
| /// Extension member method that multiplies the entity's ID by a factor. | ||
| /// </summary> | ||
| [Projectable] | ||
| public int Multiply(int factor) => e.Id * factor; | ||
| } | ||
| } | ||
|
|
||
| public static class IntExtensions | ||
| { | ||
| extension(int i) | ||
| { | ||
| /// <summary> | ||
| /// Extension member property that squares an integer. | ||
| /// </summary> | ||
| [Projectable] | ||
| public int SquaredMember => i * i; | ||
| } | ||
| } | ||
| } | ||
| #endif |
2 changes: 2 additions & 0 deletions
2
...tensionMembers/ExtensionMemberTests.ExtensionMemberMethodOnEntity.DotNet10_0.verified.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| SELECT [e].[Id] * 3 | ||
| FROM [Entity] AS [e] |
2 changes: 2 additions & 0 deletions
2
...nalTests/ExtensionMembers/ExtensionMemberTests.ExtensionMemberMethodOnEntity.verified.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| SELECT [e].[Id] * 3 | ||
| FROM [Entity] AS [e] |
2 changes: 2 additions & 0 deletions
2
...s/ExtensionMemberTests.ExtensionMemberMethodWithParameterOnEntity.DotNet10_0.verified.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| SELECT [e].[Id] * 5 | ||
| FROM [Entity] AS [e] |
2 changes: 2 additions & 0 deletions
2
...nsionMembers/ExtensionMemberTests.ExtensionMemberMethodWithParameterOnEntity.verified.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| SELECT [e].[Id] * 5 | ||
| FROM [Entity] AS [e] |
43 changes: 43 additions & 0 deletions
43
...EntityFrameworkCore.Projectables.FunctionalTests/ExtensionMembers/ExtensionMemberTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #if NET10_0_OR_GREATER | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using EntityFrameworkCore.Projectables.FunctionalTests.Helpers; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using VerifyXunit; | ||
| using Xunit; | ||
|
|
||
| namespace EntityFrameworkCore.Projectables.FunctionalTests.ExtensionMembers | ||
| { | ||
| /// <summary> | ||
| /// Tests for C# 14 extension member support. | ||
| /// These tests only run on .NET 10+ where extension members are supported. | ||
| /// Note: Extension properties cannot currently be used directly in LINQ expression trees (CS9296), | ||
| /// so only extension methods are tested here. | ||
| /// </summary> | ||
| [UsesVerify] | ||
| public class ExtensionMemberTests | ||
| { | ||
| [Fact] | ||
| public Task ExtensionMemberMethodOnEntity() | ||
| { | ||
| using var dbContext = new SampleDbContext<Entity>(); | ||
|
|
||
| var query = dbContext.Set<Entity>() | ||
| .Select(x => x.TripleId()); | ||
|
|
||
| return Verifier.Verify(query.ToQueryString()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public Task ExtensionMemberMethodWithParameterOnEntity() | ||
| { | ||
| using var dbContext = new SampleDbContext<Entity>(); | ||
|
|
||
| var query = dbContext.Set<Entity>() | ||
| .Select(x => x.Multiply(5)); | ||
|
|
||
| return Verifier.Verify(query.ToQueryString()); | ||
| } | ||
| } | ||
| } | ||
| #endif |
17 changes: 17 additions & 0 deletions
17
...or.Tests/ProjectionExpressionGeneratorTests.ExtensionMemberMethod.DotNet10_0.verified.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // <auto-generated/> | ||
| #nullable disable | ||
| using System; | ||
| using EntityFrameworkCore.Projectables; | ||
| using Foo; | ||
|
|
||
| namespace EntityFrameworkCore.Projectables.Generated | ||
| { | ||
| [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] | ||
| static class Foo_EntityExtensions_TripleId | ||
| { | ||
| static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Entity, int>> Expression() | ||
| { | ||
| return (global::Foo.Entity @this) => @this.Id * 3; | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...les.Generator.Tests/ProjectionExpressionGeneratorTests.ExtensionMemberMethod.verified.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // <auto-generated/> | ||
| #nullable disable | ||
| using System; | ||
| using EntityFrameworkCore.Projectables; | ||
| using Foo; | ||
|
|
||
| namespace EntityFrameworkCore.Projectables.Generated | ||
| { | ||
| [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] | ||
| static class Foo_EntityExtensions_TripleId | ||
| { | ||
| static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Entity, int>> Expression() | ||
| { | ||
| return (global::Foo.Entity @this) => @this.Id * 3; | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...ctionExpressionGeneratorTests.ExtensionMemberMethodWithParameters.DotNet10_0.verified.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // <auto-generated/> | ||
| #nullable disable | ||
| using System; | ||
| using EntityFrameworkCore.Projectables; | ||
| using Foo; | ||
|
|
||
| namespace EntityFrameworkCore.Projectables.Generated | ||
| { | ||
| [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] | ||
| static class Foo_EntityExtensions_Multiply | ||
| { | ||
| static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Entity, int, int>> Expression() | ||
| { | ||
| return (global::Foo.Entity @this, int factor) => @this.Id * factor; | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...Tests/ProjectionExpressionGeneratorTests.ExtensionMemberMethodWithParameters.verified.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // <auto-generated/> | ||
| #nullable disable | ||
| using System; | ||
| using EntityFrameworkCore.Projectables; | ||
| using Foo; | ||
|
|
||
| namespace EntityFrameworkCore.Projectables.Generated | ||
| { | ||
| [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] | ||
| static class Foo_EntityExtensions_Multiply | ||
| { | ||
| static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Entity, int, int>> Expression() | ||
| { | ||
| return (global::Foo.Entity @this, int factor) => @this.Id * factor; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.