Merge pull request #60 from koenbeuk/issue-54

Add support projectable members declared on generic abstract classes
This commit is contained in:
Koen
2023-02-08 02:18:59 +00:00
committed by GitHub
71 changed files with 652 additions and 720 deletions

View File

@@ -28,7 +28,7 @@ namespace EntityFrameworkCore.Projectables.Generator
visitedNode = visitedParameterSyntax.WithModifiers(node.Modifiers.RemoveAt(thisKeywordIndex)); visitedNode = visitedParameterSyntax.WithModifiers(node.Modifiers.RemoveAt(thisKeywordIndex));
} }
// Strip the parans keyword of any parameter // Strip the params keyword of any parameter
var paramsKeywordIndex = ((ParameterSyntax)visitedNode).Modifiers.IndexOf(SyntaxKind.ParamsKeyword); var paramsKeywordIndex = ((ParameterSyntax)visitedNode).Modifiers.IndexOf(SyntaxKind.ParamsKeyword);
if (paramsKeywordIndex != -1) if (paramsKeywordIndex != -1)
{ {
@@ -73,6 +73,19 @@ namespace EntityFrameworkCore.Projectables.Generator
return base.VisitIdentifierName(node); return base.VisitIdentifierName(node);
} }
public override SyntaxNode? VisitGenericName(GenericNameSyntax node)
{
var typeInfo = _semanticModel.GetTypeInfo(node);
if (typeInfo.Type is not null)
{
return SyntaxFactory.ParseTypeName(
typeInfo.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)
).WithTriviaFrom(node);
}
return base.VisitGenericName(node);
}
public override SyntaxNode? VisitQualifiedName(QualifiedNameSyntax node) public override SyntaxNode? VisitQualifiedName(QualifiedNameSyntax node)
{ {
var typeInfo = _semanticModel.GetTypeInfo(node); var typeInfo = _semanticModel.GetTypeInfo(node);

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFrameworks>netstandard2.0</TargetFrameworks>
<NoWarn>$(NoWarn);NU5128</NoWarn> <NoWarn>$(NoWarn);NU5128</NoWarn>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>

View File

@@ -11,8 +11,6 @@ namespace EntityFrameworkCore.Projectables.Generator
{ {
public class ProjectableDescriptor public class ProjectableDescriptor
{ {
public IEnumerable<string>? UsingDirectives { get; set; }
public string? ClassNamespace { get; set; } public string? ClassNamespace { get; set; }
public IEnumerable<string>? NestedInClassNames { get; set; } public IEnumerable<string>? NestedInClassNames { get; set; }
@@ -23,6 +21,10 @@ namespace EntityFrameworkCore.Projectables.Generator
public string? ClassName { get; set; } public string? ClassName { get; set; }
public TypeParameterListSyntax? ClassTypeParameterList { get; set; }
public SyntaxList<TypeParameterConstraintClauseSyntax>? ClassConstraintClauses { get; set; }
public string? MemberName { get; set; } public string? MemberName { get; set; }
public string? ReturnTypeName { get; set; } public string? ReturnTypeName { get; set; }
@@ -31,8 +33,8 @@ namespace EntityFrameworkCore.Projectables.Generator
public TypeParameterListSyntax? TypeParameterList { get; set; } public TypeParameterListSyntax? TypeParameterList { get; set; }
public IEnumerable<TypeParameterConstraintClauseSyntax>? ConstraintClauses { get; set; } public SyntaxList<TypeParameterConstraintClauseSyntax>? ConstraintClauses { get; set; }
public SyntaxNode? Body { get; set; } public ExpressionSyntax? ExpressionBody { get; set; }
} }
} }

View File

@@ -123,23 +123,52 @@ namespace EntityFrameworkCore.Projectables.Generator
ClassNamespace = memberSymbol.ContainingType.ContainingNamespace.IsGlobalNamespace ? null : memberSymbol.ContainingType.ContainingNamespace.ToDisplayString(), ClassNamespace = memberSymbol.ContainingType.ContainingNamespace.IsGlobalNamespace ? null : memberSymbol.ContainingType.ContainingNamespace.ToDisplayString(),
MemberName = memberSymbol.Name, MemberName = memberSymbol.Name,
NestedInClassNames = GetNestedInClassPath(memberSymbol.ContainingType), NestedInClassNames = GetNestedInClassPath(memberSymbol.ContainingType),
ParametersList = SyntaxFactory.ParameterList(), ParametersList = SyntaxFactory.ParameterList()
TypeParameterList = SyntaxFactory.TypeParameterList()
}; };
if (memberSymbol.ContainingType is INamedTypeSymbol { IsGenericType: true } containingNamedType)
{
descriptor.ClassTypeParameterList = SyntaxFactory.TypeParameterList();
foreach (var additionalClassTypeParameter in containingNamedType.TypeParameters)
{
descriptor.ClassTypeParameterList = descriptor.ClassTypeParameterList.AddParameters(
SyntaxFactory.TypeParameter(additionalClassTypeParameter.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))
);
if (!additionalClassTypeParameter.ConstraintTypes.IsDefaultOrEmpty)
{
descriptor.ClassConstraintClauses ??= SyntaxFactory.List<TypeParameterConstraintClauseSyntax>();
descriptor.ClassConstraintClauses = descriptor.ClassConstraintClauses.Value.Add(
SyntaxFactory.TypeParameterConstraintClause(
SyntaxFactory.IdentifierName(additionalClassTypeParameter.Name),
SyntaxFactory.SeparatedList<TypeParameterConstraintSyntax>(
additionalClassTypeParameter
.ConstraintTypes
.Select(c => SyntaxFactory.TypeConstraint(
SyntaxFactory.IdentifierName(c.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))
))
)
)
);
}
// todo: add additional type constraints
}
}
if (!member.Modifiers.Any(SyntaxKind.StaticKeyword)) if (!member.Modifiers.Any(SyntaxKind.StaticKeyword))
{ {
descriptor.ParametersList = descriptor.ParametersList.AddParameters( descriptor.ParametersList = descriptor.ParametersList.AddParameters(
SyntaxFactory.Parameter( SyntaxFactory.Parameter(
SyntaxFactory.Identifier("@this") SyntaxFactory.Identifier("@this")
).WithType( )
SyntaxFactory.ParseTypeName( .WithType(
memberSymbol.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat) SyntaxFactory.ParseTypeName(
) memberSymbol.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)
.WithTrailingTrivia(
SyntaxFactory.SyntaxTrivia(SyntaxKind.WhitespaceTrivia, " ")
)
) )
)
); );
} }
@@ -169,7 +198,7 @@ namespace EntityFrameworkCore.Projectables.Generator
var returnType = declarationSyntaxRewriter.Visit(methodDeclarationSyntax.ReturnType); var returnType = declarationSyntaxRewriter.Visit(methodDeclarationSyntax.ReturnType);
descriptor.ReturnTypeName = returnType.ToString(); descriptor.ReturnTypeName = returnType.ToString();
descriptor.Body = expressionSyntaxRewriter.Visit(methodDeclarationSyntax.ExpressionBody.Expression); descriptor.ExpressionBody = (ExpressionSyntax)expressionSyntaxRewriter.Visit(methodDeclarationSyntax.ExpressionBody.Expression);
foreach (var additionalParameter in ((ParameterListSyntax)declarationSyntaxRewriter.Visit(methodDeclarationSyntax.ParameterList)).Parameters) foreach (var additionalParameter in ((ParameterListSyntax)declarationSyntaxRewriter.Visit(methodDeclarationSyntax.ParameterList)).Parameters)
{ {
descriptor.ParametersList = descriptor.ParametersList.AddParameters(additionalParameter); descriptor.ParametersList = descriptor.ParametersList.AddParameters(additionalParameter);
@@ -177,6 +206,7 @@ namespace EntityFrameworkCore.Projectables.Generator
if (methodDeclarationSyntax.TypeParameterList is not null) if (methodDeclarationSyntax.TypeParameterList is not null)
{ {
descriptor.TypeParameterList = SyntaxFactory.TypeParameterList();
foreach (var additionalTypeParameter in ((TypeParameterListSyntax)declarationSyntaxRewriter.Visit(methodDeclarationSyntax.TypeParameterList)).Parameters) foreach (var additionalTypeParameter in ((TypeParameterListSyntax)declarationSyntaxRewriter.Visit(methodDeclarationSyntax.TypeParameterList)).Parameters)
{ {
descriptor.TypeParameterList = descriptor.TypeParameterList.AddParameters(additionalTypeParameter); descriptor.TypeParameterList = descriptor.TypeParameterList.AddParameters(additionalTypeParameter);
@@ -185,8 +215,11 @@ namespace EntityFrameworkCore.Projectables.Generator
if (methodDeclarationSyntax.ConstraintClauses.Any()) if (methodDeclarationSyntax.ConstraintClauses.Any())
{ {
descriptor.ConstraintClauses = methodDeclarationSyntax.ConstraintClauses descriptor.ConstraintClauses = SyntaxFactory.List(
.Select(x => (TypeParameterConstraintClauseSyntax)declarationSyntaxRewriter.Visit(x)); methodDeclarationSyntax
.ConstraintClauses
.Select(x => (TypeParameterConstraintClauseSyntax)declarationSyntaxRewriter.Visit(x))
);
} }
} }
else if (memberBody is PropertyDeclarationSyntax propertyDeclarationSyntax) else if (memberBody is PropertyDeclarationSyntax propertyDeclarationSyntax)
@@ -201,20 +234,13 @@ namespace EntityFrameworkCore.Projectables.Generator
var returnType = declarationSyntaxRewriter.Visit(propertyDeclarationSyntax.Type); var returnType = declarationSyntaxRewriter.Visit(propertyDeclarationSyntax.Type);
descriptor.ReturnTypeName = returnType.ToString(); descriptor.ReturnTypeName = returnType.ToString();
descriptor.Body = expressionSyntaxRewriter.Visit(propertyDeclarationSyntax.ExpressionBody.Expression); descriptor.ExpressionBody = (ExpressionSyntax)expressionSyntaxRewriter.Visit(propertyDeclarationSyntax.ExpressionBody.Expression);
} }
else else
{ {
return null; return null;
} }
descriptor.UsingDirectives =
member.SyntaxTree
.GetRoot()
.DescendantNodes()
.OfType<UsingDirectiveSyntax>()
.Select(x => x.ToString());
return descriptor; return descriptor;
} }
} }

View File

@@ -8,9 +8,11 @@ using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace EntityFrameworkCore.Projectables.Generator namespace EntityFrameworkCore.Projectables.Generator
{ {
@@ -19,6 +21,22 @@ namespace EntityFrameworkCore.Projectables.Generator
{ {
private const string ProjectablesAttributeName = "EntityFrameworkCore.Projectables.ProjectableAttribute"; private const string ProjectablesAttributeName = "EntityFrameworkCore.Projectables.ProjectableAttribute";
static readonly AttributeSyntax _editorBrowsableAttribute =
Attribute(
ParseName("global::System.ComponentModel.EditorBrowsable"),
AttributeArgumentList(
SingletonSeparatedList(
AttributeArgument(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("global::System.ComponentModel.EditorBrowsableState"),
IdentifierName("Never")
)
)
)
)
);
public void Initialize(IncrementalGeneratorInitializationContext context) public void Initialize(IncrementalGeneratorInitializationContext context)
{ {
// Do a simple filter for members // Do a simple filter for members
@@ -91,76 +109,84 @@ namespace EntityFrameworkCore.Projectables.Generator
throw new InvalidOperationException("Expected a memberName here"); throw new InvalidOperationException("Expected a memberName here");
} }
resultBuilder.Clear();
resultBuilder.AppendLine("// <auto-generated/>");
if (projectable.UsingDirectives is not null)
{
foreach (var usingDirective in projectable.UsingDirectives.Distinct())
{
resultBuilder.AppendLine(usingDirective);
}
}
if (projectable.TargetClassNamespace is not null)
{
var targetClassUsingDirective = $"using {projectable.TargetClassNamespace};";
if (!projectable.UsingDirectives.Contains(targetClassUsingDirective))
{
resultBuilder.AppendLine(targetClassUsingDirective);
}
}
if (projectable.ClassNamespace is not null && projectable.ClassNamespace != projectable.TargetClassNamespace)
{
var classUsingDirective = $"using {projectable.ClassNamespace};";
if (!projectable.UsingDirectives.Contains(classUsingDirective))
{
resultBuilder.AppendLine(classUsingDirective);
}
}
var generatedClassName = ProjectionExpressionClassNameGenerator.GenerateName(projectable.ClassNamespace, projectable.NestedInClassNames, projectable.MemberName); var generatedClassName = ProjectionExpressionClassNameGenerator.GenerateName(projectable.ClassNamespace, projectable.NestedInClassNames, projectable.MemberName);
var generatedFileName = projectable.ClassTypeParameterList is not null ? $"{generatedClassName}-{projectable.ClassTypeParameterList.ChildNodes().Count()}.g.cs" : $"{generatedClassName}.g.cs";
var lambdaTypeArguments = SyntaxFactory.TypeArgumentList( var classSyntax = ClassDeclaration(generatedClassName)
SyntaxFactory.SeparatedList( .WithModifiers(TokenList(Token(SyntaxKind.StaticKeyword)))
projectable.ParametersList?.Parameters.Where(p => p.Type is not null).Select(p => p.Type!) .WithTypeParameterList(projectable.ClassTypeParameterList)
.WithConstraintClauses(projectable.ClassConstraintClauses ?? List<TypeParameterConstraintClauseSyntax>())
.AddAttributeLists(
AttributeList()
.AddAttributes(_editorBrowsableAttribute)
) )
); .AddMembers(
MethodDeclaration(
GenericName(
Identifier("global::System.Linq.Expressions.Expression"),
TypeArgumentList(
SingletonSeparatedList(
(TypeSyntax)GenericName(
Identifier("global::System.Func"),
GetLambdaTypeArgumentListSyntax(projectable)
)
)
)
),
"Expression"
)
.WithModifiers(TokenList(Token(SyntaxKind.StaticKeyword)))
.WithTypeParameterList(projectable.TypeParameterList)
.WithConstraintClauses(projectable.ConstraintClauses ?? List<TypeParameterConstraintClauseSyntax>())
.WithBody(
Block(
ReturnStatement(
ParenthesizedLambdaExpression(
projectable.ParametersList ?? ParameterList(),
null,
projectable.ExpressionBody
)
)
)
)
);
resultBuilder.Append($@"
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
{{
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public static class {generatedClassName}
{{
public static System.Linq.Expressions.Expression<System.Func<{(lambdaTypeArguments.Arguments.Any() ? $"{lambdaTypeArguments.Arguments}, " : "")}{projectable.ReturnTypeName}>> Expression{(projectable.TypeParameterList?.Parameters.Any() == true ? projectable.TypeParameterList.ToString() : string.Empty)}()");
if (projectable.ConstraintClauses is not null) var compilationUnit = CompilationUnit()
.AddMembers(
NamespaceDeclaration(
ParseName("EntityFrameworkCore.Projectables.Generated")
).AddMembers(classSyntax)
)
.WithLeadingTrivia(
TriviaList(
Comment("// <auto-generated/>"),
Trivia(NullableDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))
)
);
context.AddSource(generatedFileName, SourceText.From(compilationUnit.NormalizeWhitespace().ToFullString(), Encoding.UTF8));
static TypeArgumentListSyntax GetLambdaTypeArgumentListSyntax(ProjectableDescriptor projectable)
{ {
foreach (var constraintClause in projectable.ConstraintClauses) var lambdaTypeArguments = TypeArgumentList(
SeparatedList(
// TODO: Document where clause
projectable.ParametersList?.Parameters.Where(p => p.Type is not null).Select(p => p.Type!)
)
);
if (projectable.ReturnTypeName is not null)
{ {
resultBuilder.Append($@" lambdaTypeArguments = lambdaTypeArguments.AddArguments(ParseTypeName(projectable.ReturnTypeName));
{constraintClause}");
} }
return lambdaTypeArguments;
} }
resultBuilder.Append($@"
{{
return {projectable.ParametersList} =>
{projectable.Body};
}}
}}
}}");
context.AddSource($"{generatedClassName}.g.cs", SourceText.From(resultBuilder.ToString(), Encoding.UTF8));
} }
} }
} }
} }

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>$(TargetFrameworkVersion)</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<PackageReadmeFile>README.md</PackageReadmeFile> <PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup> </PropertyGroup>

View File

@@ -12,6 +12,19 @@ namespace EntityFrameworkCore.Projectables.Extensions
{ {
public static class TypeExtensions public static class TypeExtensions
{ {
public static string GetSimplifiedTypeName(this Type type)
{
var name = type.Name;
var backtickIndex = name.IndexOf("`");
if (backtickIndex != -1)
{
name = name.Substring(0, backtickIndex);
}
return name;
}
public static IEnumerable<Type> GetNestedTypePath(this Type type) public static IEnumerable<Type> GetNestedTypePath(this Type type)
{ {
if (type.IsNested && type.DeclaringType is not null) if (type.IsNested && type.DeclaringType is not null)

View File

@@ -29,16 +29,40 @@ namespace EntityFrameworkCore.Projectables.Services
{ {
stringBuilder.Append(namespaceName?.Replace('.', '_')); stringBuilder.Append(namespaceName?.Replace('.', '_'));
stringBuilder.Append('_'); stringBuilder.Append('_');
var arity = 0;
if (nestedInClassNames is not null) if (nestedInClassNames is not null)
{ {
foreach (var className in nestedInClassNames) foreach (var className in nestedInClassNames)
{ {
stringBuilder.Append(className); var arityCharacterIndex = className.IndexOf('`');
if (arityCharacterIndex is -1)
{
stringBuilder.Append(className);
}
else
{
#if NETSTANDARD2_0
arity += int.Parse(className.Substring(arityCharacterIndex + 1));
#else
arity += int.Parse(className.AsSpan().Slice(arityCharacterIndex + 1));
#endif
stringBuilder.Append(className, 0, arityCharacterIndex);
}
stringBuilder.Append('_'); stringBuilder.Append('_');
} }
} }
stringBuilder.Append(memberName); stringBuilder.Append(memberName);
if (arity > 0)
{
stringBuilder.Append('`');
stringBuilder.Append(arity);
}
return stringBuilder.ToString(); return stringBuilder.ToString();
} }
} }

View File

@@ -7,6 +7,7 @@ using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using EntityFrameworkCore.Projectables.Extensions; using EntityFrameworkCore.Projectables.Extensions;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
namespace EntityFrameworkCore.Projectables.Services namespace EntityFrameworkCore.Projectables.Services
{ {
@@ -14,39 +15,39 @@ namespace EntityFrameworkCore.Projectables.Services
{ {
public LambdaExpression FindGeneratedExpression(MemberInfo projectableMemberInfo) public LambdaExpression FindGeneratedExpression(MemberInfo projectableMemberInfo)
{ {
var declaringType = projectableMemberInfo.DeclaringType ?? throw new InvalidOperationException("Expected a valid type here"); var projectableAttribute = projectableMemberInfo.GetCustomAttribute<ProjectableAttribute>()
var generatedContainingTypeName = ProjectionExpressionClassNameGenerator.GenerateFullName(declaringType.Namespace, declaringType.GetNestedTypePath().Select(x => x.Name), projectableMemberInfo.Name); ?? throw new InvalidOperationException("Expected member to have a Projectable attribute. None found");
var genericArguments = projectableMemberInfo switch { var expression = GetExpressionFromGeneratedType(projectableMemberInfo);
MethodInfo methodInfo => methodInfo.GetGenericArguments(),
_ => null
};
var expressionFactoryMethod = declaringType.Assembly.GetType(generatedContainingTypeName) if (expression is null && projectableAttribute.UseMemberBody is not null)
?.GetMethods()
?.FirstOrDefault();
if (expressionFactoryMethod is not null)
{ {
if (genericArguments is { Length: > 0 }) expression = GetExpressionFromMemberBody(projectableMemberInfo, projectableAttribute.UseMemberBody);
{
expressionFactoryMethod = expressionFactoryMethod.MakeGenericMethod(genericArguments);
}
return expressionFactoryMethod.Invoke(null, null) as LambdaExpression ?? throw new InvalidOperationException("Expected lambda");
} }
var useMemberBody = projectableMemberInfo.GetCustomAttribute<ProjectableAttribute>()?.UseMemberBody; if (expression is null)
if (useMemberBody is not null)
{ {
var exprProperty = declaringType.GetProperty(useMemberBody, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); var declaringType = projectableMemberInfo.DeclaringType ?? throw new InvalidOperationException("Expected a valid type here");
var fullName = string.Join(".", Enumerable.Empty<string>()
.Concat(new[] { declaringType.Namespace })
.Concat(declaringType.GetNestedTypePath().Select(x => x.Name))
.Concat(new[] { projectableMemberInfo.Name }));
throw new InvalidOperationException($"Unable to resolve generated expression for {fullName}.");
}
return expression;
static LambdaExpression? GetExpressionFromMemberBody(MemberInfo projectableMemberInfo, string memberName)
{
var declaringType = projectableMemberInfo.DeclaringType ?? throw new InvalidOperationException("Expected a valid type here");
var exprProperty = declaringType.GetProperty(memberName, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
var lambda = exprProperty?.GetValue(null) as LambdaExpression; var lambda = exprProperty?.GetValue(null) as LambdaExpression;
if (lambda is not null) if (lambda is not null)
{ {
if (projectableMemberInfo is PropertyInfo property && if (projectableMemberInfo is PropertyInfo property &&
lambda.Parameters.Count == 1 && lambda.Parameters.Count == 1 &&
lambda.Parameters[0].Type == declaringType && lambda.ReturnType == property.PropertyType) lambda.Parameters[0].Type == declaringType && lambda.ReturnType == property.PropertyType)
{ {
return lambda; return lambda;
@@ -59,18 +60,44 @@ namespace EntityFrameworkCore.Projectables.Services
return lambda; return lambda;
} }
} }
return null;
} }
var fullName = string.Join(".", Enumerable.Empty<string>() static LambdaExpression? GetExpressionFromGeneratedType(MemberInfo projectableMemberInfo)
.Concat(new[] { declaringType.Namespace }) {
.Concat(declaringType.GetNestedTypePath().Select(x => x.Name)) var declaringType = projectableMemberInfo.DeclaringType ?? throw new InvalidOperationException("Expected a valid type here");
.Concat(new[] { projectableMemberInfo.Name })); var generatedContainingTypeName = ProjectionExpressionClassNameGenerator.GenerateFullName(declaringType.Namespace, declaringType.GetNestedTypePath().Select(x => x.Name), projectableMemberInfo.Name);
throw new InvalidOperationException($"Unable to resolve generated expression for {fullName}.") { var expressionFactoryType = declaringType.Assembly.GetType(generatedContainingTypeName);
Data = {
["GeneratedContainingTypeName"] = generatedContainingTypeName if (expressionFactoryType is not null)
{
if (expressionFactoryType.IsGenericTypeDefinition)
{
expressionFactoryType = expressionFactoryType.MakeGenericType(declaringType.GenericTypeArguments);
}
var expressionFactoryMethod = expressionFactoryType.GetMethod("Expression", BindingFlags.Static | BindingFlags.NonPublic);
var methodGenericArguments = projectableMemberInfo switch {
MethodInfo methodInfo => methodInfo.GetGenericArguments(),
_ => null
};
if (expressionFactoryMethod is not null)
{
if (methodGenericArguments is { Length: > 0 })
{
expressionFactoryMethod = expressionFactoryMethod.MakeGenericMethod(methodGenericArguments);
}
return expressionFactoryMethod.Invoke(null, null) as LambdaExpression ?? throw new InvalidOperationException("Expected lambda");
}
} }
};
return null;
}
} }
} }
} }

View File

@@ -0,0 +1,5 @@
DECLARE @__key_0 nvarchar(4000) = N'x';
SELECT [c].[Id]
FROM [ConcreteEntity] AS [c]
WHERE CONVERT(varchar(11), [c].[Id]) = @__key_0

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EntityFrameworkCore.Projectables.FunctionalTests.Helpers;
using Microsoft.EntityFrameworkCore;
using VerifyXunit;
using Xunit;
namespace EntityFrameworkCore.Projectables.FunctionalTests.Generics
{
[UsesVerify]
public class GenericEntityTests
{
public abstract class BaseEntity<TSelf, TKey>
where TSelf : BaseEntity<TSelf, TKey>
{
public TKey Id { get; set; } = default!;
[Projectable(NullConditionalRewriteSupport = NullConditionalRewriteSupport.Ignore)]
public bool HasMatchingStringKeyConversion(string key)
=> Id?.ToString() == key;
}
public class ConcreteEntity : BaseEntity<ConcreteEntity, int>
{
}
[Fact]
public Task HasMatchingStringKeyConversion_GetsTranslated()
{
using var context = new SampleDbContext<ConcreteEntity>();
var key = "x";
var query = context.Set<ConcreteEntity>()
.Where(x => x.HasMatchingStringKeyConversion(key))
.Select(x => x.Id);
return Verifier.Verify(query.ToQueryString());
}
}
}

View File

@@ -1,18 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.C, int>> Expression()
{ {
return (global::Foo.C @this) => return (global::Foo.C @this) => 0;
0;
} }
} }
} }

View File

@@ -1,17 +1,13 @@
// <auto-generated/> // <auto-generated/>
using EntityFrameworkCore.Projectables;
using Projectables.Repro;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Projectables_Repro_Derived_Bar static class Projectables_Repro_Derived_Bar
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Projectables.Repro.Derived, string>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Projectables.Repro.Derived, string>> Expression()
{ {
return (global::Projectables.Repro.Derived @this) => return (global::Projectables.Repro.Derived @this) => @this.Foo;
@this.Foo;
} }
} }
} }

View File

@@ -1,17 +1,13 @@
// <auto-generated/> // <auto-generated/>
using EntityFrameworkCore.Projectables;
using Projectables.Repro;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Projectables_Repro_Derived_Bar static class Projectables_Repro_Derived_Bar
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Projectables.Repro.Derived, string>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Projectables.Repro.Derived, string>> Expression()
{ {
return (global::Projectables.Repro.Derived @this) => return (global::Projectables.Repro.Derived @this) => @this.Foo;
@this.Foo;
} }
} }
} }

View File

@@ -1,17 +1,13 @@
// <auto-generated/> // <auto-generated/>
using EntityFrameworkCore.Projectables;
using Projectables.Repro;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Projectables_Repro_Derived_Bar static class Projectables_Repro_Derived_Bar
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Projectables.Repro.Derived, string>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Projectables.Repro.Derived, string>> Expression()
{ {
return (global::Projectables.Repro.Derived @this) => return (global::Projectables.Repro.Derived @this) => @this.Foo();
@this.Foo();
} }
} }
} }

View File

@@ -1,17 +1,13 @@
// <auto-generated/> // <auto-generated/>
using EntityFrameworkCore.Projectables;
using Projectables.Repro;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Projectables_Repro_Derived_Bar static class Projectables_Repro_Derived_Bar
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Projectables.Repro.Derived, string>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Projectables.Repro.Derived, string>> Expression()
{ {
return (global::Projectables.Repro.Derived @this) => return (global::Projectables.Repro.Derived @this) => @this.Foo();
@this.Foo();
} }
} }
} }

View File

@@ -1,17 +1,13 @@
// <auto-generated/> // <auto-generated/>
using EntityFrameworkCore.Projectables;
using Projectables.Repro;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Projectables_Repro_SomeExtensions_AsSomeResult static class Projectables_Repro_SomeExtensions_AsSomeResult
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Projectables.Repro.SomeEntity, string>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Projectables.Repro.SomeEntity, string>> Expression()
{ {
return (global::Projectables.Repro.SomeEntity e) => return (global::Projectables.Repro.SomeEntity e) => ((global::Projectables.Repro.SuperEntity)e).Superpower;
((global::Projectables.Repro.SuperEntity)e).Superpower;
} }
} }
} }

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_Foo_IdWithBar static class Foo_Foo_IdWithBar
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Foo, int>> Expression()
{ {
return (global::Foo.Foo @this) => return (global::Foo.Foo @this) => @this.Id + global::Foo.Foo.Bar;
@this.Id + global::Foo.Foo.Bar;
} }
} }
} }

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_Foo_IdWithBar static class Foo_Foo_IdWithBar
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Foo, int>> Expression()
{ {
return (global::Foo.Foo @this) => return (global::Foo.Foo @this) => @this.Id + global::Foo.Constants.Bar;
@this.Id + global::Foo.Constants.Bar;
} }
} }
} }

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_Foo_IdWithBar static class Foo_Foo_IdWithBar
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Foo, int>> Expression()
{ {
return (global::Foo.Foo @this) => return (global::Foo.Foo @this) => @this.Id + global::Foo.Foo.Bar;
@this.Id + global::Foo.Foo.Bar;
} }
} }
} }

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_EntityExtensions_Entity_Something static class Foo_EntityExtensions_Entity_Something
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.EntityExtensions.Entity, global::Foo.EntityExtensions.Entity>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.EntityExtensions.Entity, global::Foo.EntityExtensions.Entity>> Expression()
{ {
return (global::Foo.EntityExtensions.Entity entity) => return (global::Foo.EntityExtensions.Entity entity) => entity;
entity;
} }
} }
} }

View File

@@ -1,16 +1,13 @@
// <auto-generated/> // <auto-generated/>
using EntityFrameworkCore.Projectables;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class _Foo_Calculate static class _Foo_Calculate
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo ,int, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo, int, int>> Expression()
{ {
return (global::Foo @this,int i ) => return (global::Foo @this, int i) => i;
i;
} }
} }
} }

View File

@@ -1,16 +1,13 @@
// <auto-generated/> // <auto-generated/>
using EntityFrameworkCore.Projectables;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class _SomeExtensions_Test static class _SomeExtensions_Test
{ {
public static System.Linq.Expressions.Expression<System.Func<global::SomeFlag, bool>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::SomeFlag, bool>> Expression()
{ {
return (global::SomeFlag f) => return (global::SomeFlag f) => f == global::SomeFlag.Foo;
f == global::SomeFlag.Foo;
} }
} }
} }

View File

@@ -1,18 +1,13 @@
// <auto-generated/> // <auto-generated/>
using EntityFrameworkCore.Projectables;
using System.Collections.Generic;
using Projectables.Repro;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Projectables_Repro_SomeEntity_FooOrBar static class Projectables_Repro_SomeEntity_FooOrBar
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Projectables.Repro.SomeEntity, string>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Projectables.Repro.SomeEntity, string>> Expression()
{ {
return (global::Projectables.Repro.SomeEntity @this) => return (global::Projectables.Repro.SomeEntity @this) => @this.Foo != null ? @this.Foo : @this.Bar;
@this.Foo != null ? @this.Foo : @this.Bar;
} }
} }
} }

View File

@@ -1,21 +1,14 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_EntityExtensions_EnforceString static class Foo_EntityExtensions_EnforceString
{ {
public static System.Linq.Expressions.Expression<System.Func<T, string>> Expression<T>() static global::System.Linq.Expressions.Expression<global::System.Func<T, string>> Expression<T>()
where T : unmanaged where T : unmanaged
{ {
return (T value) => return (T value) => value.ToString();
value.ToString();
} }
} }
} }

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Collections.Generic;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_NextFoo static class Foo_C_NextFoo
{ {
public static System.Linq.Expressions.Expression<System.Func<List<object> ,List<int?>, List<object>>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::System.Collections.Generic.List<object>, global::System.Collections.Generic.List<int?>, global::System.Collections.Generic.List<object>>> Expression()
{ {
return (List<object> input,List<int?> nullablePrimitiveArgument) => return (global::System.Collections.Generic.List<object> input, global::System.Collections.Generic.List<int?> nullablePrimitiveArgument) => input;
input;
} }
} }
} }

View File

@@ -0,0 +1,13 @@
// <auto-generated/>
#nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
static class _EntiyBase_GetId<TId>
{
static global::System.Linq.Expressions.Expression<global::System.Func<TId>> Expression()
{
return () => default;
}
}
}

View File

@@ -0,0 +1,14 @@
// <auto-generated/>
#nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
static class _EntityBase_GetId<TId>
where TId : global::System.ICloneable
{
static global::System.Linq.Expressions.Expression<global::System.Func<TId>> Expression()
{
return () => default;
}
}
}

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_Bar_ProjectedId static class Foo_Bar_ProjectedId
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Bar, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Bar, int>> Expression()
{ {
return (global::Foo.Bar @this) => return (global::Foo.Bar @this) => @this.Id;
@this.Id;
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_A_IsB static class Foo_A_IsB
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.A, bool>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.A, bool>> Expression()
{ {
return (global::Foo.A @this) => return (global::Foo.A @this) => @this is global::Foo.B;
@this is global::Foo.B;
} }
} }
} }

View File

@@ -1,18 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.C, int>> Expression()
{ {
return (global::Foo.C @this) => return (global::Foo.C @this) => @this.Bar;
@this.Bar;
} }
} }
} }

View File

@@ -1,22 +1,14 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_EntityExtensions_Entity_Something static class Foo_EntityExtensions_Entity_Something
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.EntityExtensions.Entity, global::Foo.EntityExtensions.Entity>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.EntityExtensions.Entity, global::Foo.EntityExtensions.Entity>> Expression()
{ {
return (global::Foo.EntityExtensions.Entity entity) => return (global::Foo.EntityExtensions.Entity entity) => new Entity(entity.Id)
new Entity(entity.Id) { {FullName = entity.FullName};
FullName = entity.FullName
};
} }
} }
} }

View File

@@ -1,18 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.C, int>> Expression()
{ {
return (global::Foo.C @this) => return (global::Foo.C @this) => @this.Bar + @this.Bar + @this.Bar;
@this.Bar + @this.Bar + @this.Bar;
} }
} }
} }

View File

@@ -1,18 +1,13 @@
// <auto-generated/> // <auto-generated/>
using EntityFrameworkCore.Projectables;
using System.Collections.Generic;
using Projectables.Repro;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Projectables_Repro_SomeEntity_RootChildren static class Projectables_Repro_SomeEntity_RootChildren
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Projectables.Repro.SomeEntity, ICollection<global::Projectables.Repro.SomeEntity>>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Projectables.Repro.SomeEntity, global::System.Collections.Generic.ICollection<global::Projectables.Repro.SomeEntity>>> Expression()
{ {
return (global::Projectables.Repro.SomeEntity @this) => return (global::Projectables.Repro.SomeEntity @this) => @this.Parent != null ? @this.Parent.RootChildren : @this.Children;
@this.Parent != null ? @this.Parent.RootChildren : @this.Children;
} }
} }
} }

View File

@@ -1,16 +1,13 @@
// <auto-generated/> // <auto-generated/>
using EntityFrameworkCore.Projectables;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class _Foo_SomeNumber static class _Foo_SomeNumber
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo, int>> Expression()
{ {
return (global::Foo fancyClass) => return (global::Foo fancyClass) => fancyClass != null ? (fancyClass.FancyNumber) : ( int ? )null ?? 3;
fancyClass != null ? (fancyClass.FancyNumber ) : (int?)null ?? 3;
} }
} }
} }

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_EntityExtensions_GetFirstRelatedIgnoreNulls static class Foo_EntityExtensions_GetFirstRelatedIgnoreNulls
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.EntityExtensions.Entity, global::Foo.EntityExtensions.Entity>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.EntityExtensions.Entity, global::Foo.EntityExtensions.Entity>> Expression()
{ {
return (global::Foo.EntityExtensions.Entity entity) => return (global::Foo.EntityExtensions.Entity entity) => entity.RelatedEntities[0];
entity.RelatedEntities[0];
} }
} }
} }

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_EntityExtensions_GetFirstRelatedIgnoreNulls static class Foo_EntityExtensions_GetFirstRelatedIgnoreNulls
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.EntityExtensions.Entity, global::Foo.EntityExtensions.Entity>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.EntityExtensions.Entity, global::Foo.EntityExtensions.Entity>> Expression()
{ {
return (global::Foo.EntityExtensions.Entity entity) => return (global::Foo.EntityExtensions.Entity entity) => entity != null ? (entity.RelatedEntities != null ? (entity.RelatedEntities[0]) : (global::Foo.EntityExtensions.Entity)null) : (global::Foo.EntityExtensions.Entity)null;
entity != null ? (entity.RelatedEntities != null ? (entity.RelatedEntities[0]) : (global::Foo.EntityExtensions.Entity)null) : (global::Foo.EntityExtensions.Entity)null;
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_GetFirst static class Foo_C_GetFirst
{ {
public static System.Linq.Expressions.Expression<System.Func<string, string>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<string, string>> Expression()
{ {
return (string input) => return (string input) => input[0].ToString();
input[0].ToString();
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_GetFirst static class Foo_C_GetFirst
{ {
public static System.Linq.Expressions.Expression<System.Func<string, string>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<string, string>> Expression()
{ {
return (string input) => return (string input) => input != null ? (input[0].ToString()) : ( string )null;
input != null ? (input[0].ToString()) : (string)null;
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_GetLength static class Foo_C_GetLength
{ {
public static System.Linq.Expressions.Expression<System.Func<string, int?>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<string, int?>> Expression()
{ {
return (string input) => return (string input) => input.Length;
input.Length;
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_GetLength static class Foo_C_GetLength
{ {
public static System.Linq.Expressions.Expression<System.Func<string, int?>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<string, int?>> Expression()
{ {
return (string input) => return (string input) => input != null ? (input.Length) : ( int ? )null;
input != null ? (input.Length) : (int?)null;
} }
} }
} }

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_EntityExtensions_GetFirstName static class Foo_EntityExtensions_GetFirstName
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.EntityExtensions.Entity, string>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.EntityExtensions.Entity, string>> Expression()
{ {
return (global::Foo.EntityExtensions.Entity entity) => return (global::Foo.EntityExtensions.Entity entity) => entity.FullName != null ? (entity.FullName.Substring(entity.FullName != null ? (entity.FullName.IndexOf(' ')) : ( int ? )null ?? 0)) : ( string )null;
entity.FullName != null ? (entity.FullName.Substring(entity.FullName != null ? (entity.FullName.IndexOf(' ') ) : (int?)null ?? 0)) : (string)null;
} }
} }
} }

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Collections.Generic;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_NullableReferenceType static class Foo_C_NullableReferenceType
{ {
public static System.Linq.Expressions.Expression<System.Func<object, string>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<object, string>> Expression()
{ {
return (object input) => return (object input) => (string)input;
(string)input;
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_NextFoo static class Foo_C_NextFoo
{ {
public static System.Linq.Expressions.Expression<System.Func<object ,int?, object>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<object, int?, object>> Expression()
{ {
return (object unusedArgument,int? nullablePrimitiveArgument) => return (object unusedArgument, int? nullablePrimitiveArgument) => null;
null;
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_GetFirst static class Foo_C_GetFirst
{ {
public static System.Linq.Expressions.Expression<System.Func<string, char?>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<string, char?>> Expression()
{ {
return (string input) => return (string input) => input[0];
input[0];
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_GetFirst static class Foo_C_GetFirst
{ {
public static System.Linq.Expressions.Expression<System.Func<string, char?>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<string, char?>> Expression()
{ {
return (string input) => return (string input) => input != null ? (input[0]) : ( char ? )null;
input != null ? (input[0]) : (char?)null;
} }
} }
} }

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Collections.Generic;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_NullableValueType static class Foo_C_NullableValueType
{ {
public static System.Linq.Expressions.Expression<System.Func<object, int?>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<object, int?>> Expression()
{ {
return (object input) => return (object input) => (int? )input;
(int?)input;
} }
} }
} }

View File

@@ -1,16 +0,0 @@
// <auto-generated/>
using EntityFrameworkCore.Projectables;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable
{
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public static class _Foo_First
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo ,int[], int>> Expression()
{
return (global::Foo @this, int[] numbers) =>
numbers[0];
}
}
}

View File

@@ -1,16 +1,13 @@
// <auto-generated/> // <auto-generated/>
using EntityFrameworkCore.Projectables;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class _Foo_First static class _Foo_First
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo ,int[], int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo, int[], int>> Expression()
{ {
return (global::Foo @this,int[] all) => return (global::Foo @this, int[] all) => all[0];
all[0];
} }
} }
} }

View File

@@ -1,18 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C ,int ,string ,object, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.C, int, string, object, int>> Expression()
{ {
return (global::Foo.C @this,int a,string b,object d) => return (global::Foo.C @this, int a, string b, object d) => a;
a;
} }
} }
} }

View File

@@ -1,18 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C ,int, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.C, int, int>> Expression()
{ {
return (global::Foo.C @this,int i) => return (global::Foo.C @this, int i) => i;
i;
} }
} }
} }

View File

@@ -1,18 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.C, int>> Expression()
{ {
return (global::Foo.C @this) => return (global::Foo.C @this) => @this.Bar();
@this.Bar();
} }
} }
} }

View File

@@ -1,18 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.C, int>> Expression()
{ {
return (global::Foo.C @this) => return (global::Foo.C @this) => @this.Bar;
@this.Bar;
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.D, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.D, int>> Expression()
{ {
return (global::Foo.D d) => return (global::Foo.D d) => 1;
1;
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<int, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<int, int>> Expression()
{ {
return (int i) => return (int i) => i;
i;
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo1 static class Foo_C_Foo1
{ {
public static System.Linq.Expressions.Expression<System.Func<int, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<int, int>> Expression()
{ {
return (int i) => return (int i) => i;
i;
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo1 static class Foo_C_Foo1
{ {
public static System.Linq.Expressions.Expression<System.Func<object, object>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<object, object>> Expression()
{ {
return (object i) => return (object i) => global::Foo.C.Foo1(i);
global::Foo.C.Foo1(i);
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, global::Foo.D>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.C, global::Foo.D>> Expression()
{ {
return (global::Foo.C @this) => return (global::Foo.C @this) => global::System.Linq.Enumerable.First(@this.Dees);
global::System.Linq.Enumerable.First(@this.Dees);
} }
} }
} }

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foos;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foos_Bar_FooId static class Foos_Bar_FooId
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foos.Bar, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foos.Bar, int>> Expression()
{ {
return (global::Foos.Bar @this) => return (global::Foos.Bar @this) => @this.Foo.Id;
@this.Foo.Id;
} }
} }
} }

View File

@@ -1,17 +1,13 @@
// <auto-generated/> // <auto-generated/>
using EntityFrameworkCore.Projectables;
using One.Two;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class One_Two_Bar_Method static class One_Two_Bar_Method
{ {
public static System.Linq.Expressions.Expression<System.Func<global::One.Two.Bar, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::One.Two.Bar, int>> Expression()
{ {
return (global::One.Two.Bar @this) => return (global::One.Two.Bar @this) => global::One.IntExtensions.AddOne(1);
global::One.IntExtensions.AddOne(1);
} }
} }
} }

View File

@@ -1,18 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_D_Foo static class Foo_C_D_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C.D, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.C.D, int>> Expression()
{ {
return (global::Foo.C.D @this) => return (global::Foo.C.D @this) => @this.Bar + 1;
@this.Bar + 1;
} }
} }
} }

View File

@@ -1,18 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.C, int>> Expression()
{ {
return (global::Foo.C @this) => return (global::Foo.C @this) => @this.Bar + 1;
@this.Bar + 1;
} }
} }
} }

View File

@@ -1,18 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.C, int>> Expression()
{ {
return (global::Foo.C @this) => return (global::Foo.C @this) => 1;
1;
} }
} }
} }

View File

@@ -1,18 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.C, int>> Expression()
{ {
return (global::Foo.C @this) => return (global::Foo.C @this) => 1;
1;
} }
} }
} }

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_Foo_IdWithBar static class Foo_Foo_IdWithBar
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Foo, int>> Expression()
{ {
return (global::Foo.Foo @this) => return (global::Foo.Foo @this) => @this.Id + global::Foo.Foo.Bar;
@this.Id + global::Foo.Foo.Bar;
} }
} }
} }

View File

@@ -1,20 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_Foo_IdWithBar static class Foo_Foo_IdWithBar
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.Foo, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Foo, int>> Expression()
{ {
return (global::Foo.Foo @this) => return (global::Foo.Foo @this) => @this.Id + global::Foo.Constants.Bar;
@this.Id + global::Foo.Constants.Bar;
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class _Foo_Zero static class _Foo_Zero
{ {
public static System.Linq.Expressions.Expression<System.Func<int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<int>> Expression()
{ {
return () => return () => 0;
0;
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class _Foo_Zero static class _Foo_Zero
{ {
public static System.Linq.Expressions.Expression<System.Func<int, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<int, int>> Expression()
{ {
return (int x) => return (int x) => 0;
0;
} }
} }
} }

View File

@@ -1,19 +1,13 @@
// <auto-generated/> // <auto-generated/>
using System;
using System.Linq;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable #nullable disable
namespace EntityFrameworkCore.Projectables.Generated
{ {
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public static class Foo_C_Foo static class Foo_C_Foo
{ {
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression() static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.C, int>> Expression()
{ {
return (global::Foo.C @this) => return (global::Foo.C @this) => global::System.Linq.Enumerable.Count(global::System.Linq.Enumerable.OfType<D>(@this.Dees));
global::System.Linq.Enumerable.Count(global::System.Linq.Enumerable.OfType<D>(@this.Dees));
} }
} }
} }

View File

@@ -1,5 +1,8 @@
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@@ -537,6 +540,7 @@ namespace Foo {
return Verifier.Verify(result.GeneratedTrees[0].ToString()); return Verifier.Verify(result.GeneratedTrees[0].ToString());
} }
[Fact] [Fact]
public Task GenericNullableReferenceTypesAreBeingEliminated() public Task GenericNullableReferenceTypesAreBeingEliminated()
{ {
@@ -1566,6 +1570,52 @@ class Foo {
return Verifier.Verify(result.GeneratedTrees[0].ToString()); return Verifier.Verify(result.GeneratedTrees[0].ToString());
} }
[Fact]
public Task GenericTypes()
{
// issue: https://github.com/koenbeuk/EntityFrameworkCore.Projectables/issues/48
var compilation = CreateCompilation(@"
using EntityFrameworkCore.Projectables;
class EntiyBase<TId> {
[Projectable]
public static TId GetId() => default;
}
");
var result = RunGenerator(compilation);
Assert.Empty(result.Diagnostics);
Assert.Single(result.GeneratedTrees);
return Verifier.Verify(result.GeneratedTrees[0].ToString());
}
[Fact]
public Task GenericTypesWithConstraints()
{
// issue: https://github.com/koenbeuk/EntityFrameworkCore.Projectables/issues/48
var compilation = CreateCompilation(@"
using System;
using EntityFrameworkCore.Projectables;
class EntityBase<TId> where TId : ICloneable, new() {
[Projectable]
public static TId GetId() => default;
}
");
var result = RunGenerator(compilation);
Assert.Empty(result.Diagnostics);
Assert.Single(result.GeneratedTrees);
return Verifier.Verify(result.GeneratedTrees[0].ToString());
}
#region Helpers #region Helpers
Compilation CreateCompilation(string source, bool expectedToCompile = true) Compilation CreateCompilation(string source, bool expectedToCompile = true)

View File

@@ -14,6 +14,8 @@ namespace EntityFrameworkCore.Projectables.Tests.Services
[InlineData("ns", new string[] { "a" }, "m", "ns_a_m")] [InlineData("ns", new string[] { "a" }, "m", "ns_a_m")]
[InlineData("ns", new string[] { "a", "b" }, "m", "ns_a_b_m")] [InlineData("ns", new string[] { "a", "b" }, "m", "ns_a_b_m")]
[InlineData(null, new string[] { "a" }, "m", "_a_m")] [InlineData(null, new string[] { "a" }, "m", "_a_m")]
[InlineData("ns", new string[] { "a`1" }, "m", "ns_a_m`1" )]
[InlineData("ns", new string[] { "a`1", "b`1" }, "m", "ns_a_b_m`2")]
public void GenerateName(string? namespaceName, string[] nestedTypeNames, string memberName, string expected) public void GenerateName(string? namespaceName, string[] nestedTypeNames, string memberName, string expected)
{ {
var result = ProjectionExpressionClassNameGenerator.GenerateName(namespaceName, nestedTypeNames, memberName); var result = ProjectionExpressionClassNameGenerator.GenerateName(namespaceName, nestedTypeNames, memberName);