Skip to content

Commit d6b1cfb

Browse files
authored
Merge pull request #68 from koenbeuk/issue-65
Import using directives to help resolve extension methods
2 parents 0820252 + 458509c commit d6b1cfb

File tree

60 files changed

+280
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+280
-1
lines changed

src/EntityFrameworkCore.Projectables.Generator/ProjectableDescriptor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace EntityFrameworkCore.Projectables.Generator
1111
{
1212
public class ProjectableDescriptor
1313
{
14+
public IEnumerable<UsingDirectiveSyntax>? UsingDirectives { get; set; }
15+
1416
public string? ClassNamespace { get; set; }
1517

1618
public IEnumerable<string>? NestedInClassNames { get; set; }

src/EntityFrameworkCore.Projectables.Generator/ProjectableInterpreter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ x is IPropertySymbol xProperty &&
119119
var declarationSyntaxRewriter = new DeclarationSyntaxRewriter(semanticModel);
120120

121121
var descriptor = new ProjectableDescriptor {
122+
123+
UsingDirectives = member.SyntaxTree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>(),
122124
ClassName = memberSymbol.ContainingType.Name,
123125
ClassNamespace = memberSymbol.ContainingType.ContainingNamespace.IsGlobalNamespace ? null : memberSymbol.ContainingType.ContainingNamespace.ToDisplayString(),
124126
MemberName = memberSymbol.Name,

src/EntityFrameworkCore.Projectables.Generator/ProjectionExpressionGenerator.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,23 @@ static void Execute(Compilation compilation, ImmutableArray<MemberDeclarationSyn
153153

154154
#nullable disable
155155

156-
var compilationUnit = CompilationUnit()
156+
var compilationUnit = CompilationUnit();
157+
158+
foreach (var usingDirective in projectable.UsingDirectives)
159+
{
160+
compilationUnit = compilationUnit.AddUsings(usingDirective);
161+
}
162+
163+
if (projectable.ClassNamespace is not null)
164+
{
165+
compilationUnit = compilationUnit.AddUsings(
166+
UsingDirective(
167+
ParseName(projectable.ClassNamespace)
168+
)
169+
);
170+
}
171+
172+
compilationUnit = compilationUnit
157173
.AddMembers(
158174
NamespaceDeclaration(
159175
ParseName("EntityFrameworkCore.Projectables.Generated")

tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ArgumentlessProjectableComputedMethod.verified.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// <auto-generated/>
22
#nullable disable
3+
using System;
4+
using EntityFrameworkCore.Projectables;
5+
using Foo;
6+
37
namespace EntityFrameworkCore.Projectables.Generated
48
{
59
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]

tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.BaseMemberExplicitReference.verified.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// <auto-generated/>
22
#nullable disable
3+
using EntityFrameworkCore.Projectables;
4+
using Projectables.Repro;
5+
36
namespace EntityFrameworkCore.Projectables.Generated
47
{
58
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]

tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.BaseMemberImplicitReference.verified.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// <auto-generated/>
22
#nullable disable
3+
using EntityFrameworkCore.Projectables;
4+
using Projectables.Repro;
5+
36
namespace EntityFrameworkCore.Projectables.Generated
47
{
58
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]

tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.BaseMethodExplicitReference.verified.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// <auto-generated/>
22
#nullable disable
3+
using EntityFrameworkCore.Projectables;
4+
using Projectables.Repro;
5+
36
namespace EntityFrameworkCore.Projectables.Generated
47
{
58
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]

tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.BaseMethorImplicitReference.verified.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// <auto-generated/>
22
#nullable disable
3+
using EntityFrameworkCore.Projectables;
4+
using Projectables.Repro;
5+
36
namespace EntityFrameworkCore.Projectables.Generated
47
{
58
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]

tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.Cast.verified.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// <auto-generated/>
22
#nullable disable
3+
using EntityFrameworkCore.Projectables;
4+
using Projectables.Repro;
5+
36
namespace EntityFrameworkCore.Projectables.Generated
47
{
58
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]

tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ConstMember.verified.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// <auto-generated/>
22
#nullable disable
3+
using System;
4+
using System.Linq;
5+
using System.Collections.Generic;
6+
using EntityFrameworkCore.Projectables;
7+
using Foo;
8+
39
namespace EntityFrameworkCore.Projectables.Generated
410
{
511
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]

0 commit comments

Comments
 (0)