mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-05-30 05:21:16 +00:00
Fixed code gen issue for Projectable extension methods using other projectable extension methods
This commit is contained in:
@@ -51,7 +51,17 @@ namespace EntityFrameworkCore.Projectables.Generator
|
|||||||
|
|
||||||
if (symbolInfo.Symbol is not null)
|
if (symbolInfo.Symbol is not null)
|
||||||
{
|
{
|
||||||
if (symbolInfo.Symbol.Kind is SymbolKind.Property or SymbolKind.Method or SymbolKind.Field && SymbolEqualityComparer.Default.Equals(symbolInfo.Symbol.ContainingType, _targetTypeSymbol))
|
if (symbolInfo.Symbol is IMethodSymbol methodSymbol && methodSymbol.IsExtensionMethod)
|
||||||
|
{
|
||||||
|
if (SymbolEqualityComparer.Default.Equals(symbolInfo.Symbol.ContainingType, _targetTypeSymbol))
|
||||||
|
{
|
||||||
|
//return SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
|
||||||
|
// methodSymbol.ReducedFrom.Sym
|
||||||
|
//);
|
||||||
|
//throw new Exception("foo");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (symbolInfo.Symbol.Kind is SymbolKind.Property or SymbolKind.Method or SymbolKind.Field && SymbolEqualityComparer.Default.Equals(symbolInfo.Symbol.ContainingType, _targetTypeSymbol))
|
||||||
{
|
{
|
||||||
return SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
|
return SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
|
||||||
SyntaxFactory.IdentifierName("@this"),
|
SyntaxFactory.IdentifierName("@this"),
|
||||||
|
|||||||
+3
@@ -11,6 +11,9 @@ namespace EntityFrameworkCore.Projectables.FunctionalTests.ExtensionMethods
|
|||||||
[Projectable]
|
[Projectable]
|
||||||
public static int Foo(this Entity entity) => entity.Id + 1;
|
public static int Foo(this Entity entity) => entity.Id + 1;
|
||||||
|
|
||||||
|
[Projectable]
|
||||||
|
public static int Foo2(this Entity entity) => entity.Foo() + 1;
|
||||||
|
|
||||||
[Projectable]
|
[Projectable]
|
||||||
public static Entity? LeadingEntity(this Entity entity, DbContext dbContext)
|
public static Entity? LeadingEntity(this Entity entity, DbContext dbContext)
|
||||||
=> dbContext.Set<Entity>().Where(y => y.Id > entity.Id).FirstOrDefault();
|
=> dbContext.Set<Entity>().Where(y => y.Id > entity.Id).FirstOrDefault();
|
||||||
|
|||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
SELECT ([e].[Id] + 1) + 1
|
||||||
|
FROM [Entity] AS [e]
|
||||||
+11
@@ -38,6 +38,17 @@ namespace EntityFrameworkCore.Projectables.FunctionalTests.ExtensionMethods
|
|||||||
return Verifier.Verify(query.ToQueryString());
|
return Verifier.Verify(query.ToQueryString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public Task SelectProjectableExtensionMethod2()
|
||||||
|
{
|
||||||
|
using var dbContext = new SampleDbContext<Entity>();
|
||||||
|
|
||||||
|
var query = dbContext.Set<Entity>()
|
||||||
|
.Select(x => x.Foo2());
|
||||||
|
|
||||||
|
return Verifier.Verify(query.ToQueryString());
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task ExtensionMethodAcceptingDbContext()
|
public Task ExtensionMethodAcceptingDbContext()
|
||||||
{
|
{
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using EntityFrameworkCore.Projectables;
|
||||||
|
using Foo;
|
||||||
|
|
||||||
|
namespace EntityFrameworkCore.Projectables.Generated
|
||||||
|
#nullable disable
|
||||||
|
{
|
||||||
|
public static class Foo_C_Foo1
|
||||||
|
{
|
||||||
|
public static System.Linq.Expressions.Expression<System.Func<int, int>> Expression =>
|
||||||
|
(int i) => i;
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using EntityFrameworkCore.Projectables;
|
||||||
|
using Foo;
|
||||||
|
|
||||||
|
namespace EntityFrameworkCore.Projectables.Generated
|
||||||
|
#nullable disable
|
||||||
|
{
|
||||||
|
public static class Foo_C_Foo1
|
||||||
|
{
|
||||||
|
public static System.Linq.Expressions.Expression<System.Func<object, object>> Expression =>
|
||||||
|
(object i) => i.Foo1();
|
||||||
|
}
|
||||||
|
}
|
||||||
+50
@@ -367,6 +367,56 @@ namespace Foo {
|
|||||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public Task ProjectableExtensionMethod3()
|
||||||
|
{
|
||||||
|
var compilation = CreateCompilation(@"
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using EntityFrameworkCore.Projectables;
|
||||||
|
namespace Foo {
|
||||||
|
static class C {
|
||||||
|
[Projectable]
|
||||||
|
public static int Foo1(this int i) => i;
|
||||||
|
|
||||||
|
[Projectable]
|
||||||
|
public static int Foo2(this int i) => i.Foo1();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
");
|
||||||
|
|
||||||
|
var result = RunGenerator(compilation);
|
||||||
|
|
||||||
|
Assert.Empty(result.Diagnostics);
|
||||||
|
Assert.Equal(2, result.GeneratedTrees.Length);
|
||||||
|
|
||||||
|
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public Task ProjectableExtensionMethod4()
|
||||||
|
{
|
||||||
|
var compilation = CreateCompilation(@"
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using EntityFrameworkCore.Projectables;
|
||||||
|
namespace Foo {
|
||||||
|
static class C {
|
||||||
|
[Projectable]
|
||||||
|
public static object Foo1(this object i) => i.Foo1();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
");
|
||||||
|
|
||||||
|
var result = RunGenerator(compilation);
|
||||||
|
|
||||||
|
Assert.Empty(result.Diagnostics);
|
||||||
|
Assert.Single(result.GeneratedTrees);
|
||||||
|
|
||||||
|
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void BlockBodiedMember_RaisesDiagnostics()
|
public void BlockBodiedMember_RaisesDiagnostics()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user