This commit is contained in:
Koen Bekkenutte
2021-11-05 05:30:45 +08:00
45 changed files with 373 additions and 96 deletions
@@ -15,21 +15,6 @@ namespace EntityFrameworkCore.Projectables.Generator
_semanticModel = semanticModel;
}
public override SyntaxNode? VisitIdentifierName(IdentifierNameSyntax node)
{
var visitedNode = base.VisitIdentifierName(node);
var symbolInfo = _semanticModel.GetSymbolInfo(visitedNode);
if (symbolInfo.Symbol is not null)
{
return SyntaxFactory.IdentifierName(symbolInfo.Symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))
.WithTriviaFrom(node);
}
return visitedNode;
}
public override SyntaxNode? VisitParameter(ParameterSyntax node)
{
var visitedNode = base.VisitParameter(node);
@@ -2,6 +2,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -28,6 +29,10 @@ namespace EntityFrameworkCore.Projectables.Generator
public ParameterListSyntax ParametersList { get; set; }
public TypeParameterListSyntax TypeParameterList { get; set; }
public IEnumerable<TypeParameterConstraintClauseSyntax> ConstraintClauses { get; set; }
public SyntaxNode Body { get; set; }
}
}
@@ -59,7 +59,8 @@ namespace EntityFrameworkCore.Projectables.Generator
ClassNamespace = memberSymbol.ContainingType.ContainingNamespace.IsGlobalNamespace ? null : memberSymbol.ContainingType.ContainingNamespace.ToDisplayString(),
MemberName = memberSymbol.Name,
NestedInClassNames = GetNestedInClassPath(memberSymbol.ContainingType),
ParametersList = SyntaxFactory.ParameterList()
ParametersList = SyntaxFactory.ParameterList(),
TypeParameterList = SyntaxFactory.TypeParameterList()
};
if (!memberDeclarationSyntax.Modifiers.Any(SyntaxKind.StaticKeyword))
@@ -78,7 +79,9 @@ namespace EntityFrameworkCore.Projectables.Generator
);
}
if (memberSymbol is IMethodSymbol methodSymbol && methodSymbol.IsExtensionMethod)
var methodSymbol = memberSymbol as IMethodSymbol;
if (methodSymbol is { IsExtensionMethod: true })
{
var targetTypeSymbol = methodSymbol.Parameters.First().Type;
descriptor.TargetClassNamespace = targetTypeSymbol.ContainingNamespace.IsGlobalNamespace ? null : targetTypeSymbol.ContainingNamespace.ToDisplayString();
@@ -107,6 +110,20 @@ namespace EntityFrameworkCore.Projectables.Generator
{
descriptor.ParametersList = descriptor.ParametersList.AddParameters(additionalParameter);
}
if (methodDeclarationSyntax.TypeParameterList is not null)
{
foreach (var additionalTypeParameter in ((TypeParameterListSyntax)declarationSyntaxRewriter.Visit(methodDeclarationSyntax.TypeParameterList)).Parameters)
{
descriptor.TypeParameterList = descriptor.TypeParameterList.AddParameters(additionalTypeParameter);
}
}
if (methodDeclarationSyntax.ConstraintClauses.Any())
{
descriptor.ConstraintClauses = methodDeclarationSyntax.ConstraintClauses
.Select(x => (TypeParameterConstraintClauseSyntax)declarationSyntaxRewriter.Visit(x));
}
}
else if (memberDeclarationSyntax is PropertyDeclarationSyntax propertyDeclarationSyntax)
{
@@ -72,11 +72,26 @@ namespace EntityFrameworkCore.Projectables.Generated
{{
public static class {generatedClassName}
{{
public static System.Linq.Expressions.Expression<System.Func<{lambdaTypeArguments.Arguments}, {projectable.ReturnTypeName}>> Expression =>
{projectable.ParametersList} => {projectable.Body};
public static System.Linq.Expressions.Expression<System.Func<{lambdaTypeArguments.Arguments}, {projectable.ReturnTypeName}>> Expression{(projectable.TypeParameterList.Parameters.Any() ? projectable.TypeParameterList.ToString() : string.Empty)}()");
if (projectable.ConstraintClauses is not null)
{
foreach (var constraintClause in projectable.ConstraintClauses)
{
resultBuilder.Append($@"
{constraintClause}");
}
}
resultBuilder.Append($@"
{{
return {projectable.ParametersList} =>
{projectable.Body};
}}
}}
}}");
context.AddSource($"{generatedClassName}_Generated", SourceText.From(resultBuilder.ToString(), Encoding.UTF8));
}
}
@@ -12,31 +12,37 @@ namespace EntityFrameworkCore.Projectables.Services
{
public sealed class ProjectionExpressionResolver : IProjectionExpressionResolver
{
readonly ConcurrentDictionary<string, LambdaExpression> _lookupCache = new();
public LambdaExpression FindGeneratedExpression(MemberInfo projectableMemberInfo)
{
var reflectedType = projectableMemberInfo.ReflectedType ?? throw new InvalidOperationException("Expected a valid type here");
var generatedContainingTypeName = ProjectionExpressionClassNameGenerator.GenerateFullName(reflectedType.Namespace, reflectedType.GetNestedTypePath().Select(x => x.Name), projectableMemberInfo.Name);
return _lookupCache.GetOrAdd(generatedContainingTypeName, _ => {
var expressionFactoryMethod = reflectedType.Assembly
.GetTypes()
.Where(x => x.FullName == generatedContainingTypeName)
.SelectMany(x => x.GetMethods())
.FirstOrDefault();
var genericArguments = projectableMemberInfo switch {
MethodInfo methodInfo => methodInfo.GetGenericArguments(),
_ => null
};
if (expressionFactoryMethod is null)
{
throw new InvalidOperationException("Unable to resolve generated expression") {
Data = {
["GeneratedContainingTypeName"] = generatedContainingTypeName
}
};
}
var expressionFactoryMethod = reflectedType.Assembly
.GetTypes()
.Where(x => x.FullName == generatedContainingTypeName)
.SelectMany(x => x.GetMethods())
.FirstOrDefault();
return expressionFactoryMethod.Invoke(null, null) as LambdaExpression ?? throw new InvalidOperationException("Expected lambda");
});
if (expressionFactoryMethod is null)
{
throw new InvalidOperationException("Unable to resolve generated expression") {
Data = {
["GeneratedContainingTypeName"] = generatedContainingTypeName
}
};
}
if (genericArguments is { Length: > 0 } )
{
expressionFactoryMethod = expressionFactoryMethod.MakeGenericMethod(genericArguments);
}
return expressionFactoryMethod.Invoke(null, null) as LambdaExpression ?? throw new InvalidOperationException("Expected lambda");
}
}
}
@@ -63,4 +63,4 @@ namespace EntityFrameworkCore.Projectables.FunctionalTests.ExtensionMethods
return Verifier.Verify(query.ToQueryString());
}
}
}
}
@@ -0,0 +1,8 @@
namespace EntityFrameworkCore.Projectables.FunctionalTests.Generics
{
public record Entity : IEntity
{
public int Id { get; set; }
public string? Name { get; set; }
}
}
@@ -0,0 +1,11 @@
using System.Linq;
namespace EntityFrameworkCore.Projectables.FunctionalTests.Generics
{
public static class EntityExtensions
{
[Projectable]
public static TEntity? DefaultIfIdIsNegative<TEntity>(this TEntity entity) where TEntity : IEntity
=> entity.Id >= 0 ? entity : default;
}
}
@@ -0,0 +1,26 @@
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 GenericFunctionTests
{
[Fact]
public Task DefaultIfIdIsNegative()
{
using var context = new SampleDbContext<Entity>();
var query = context.Set<Entity>()
.Select(x => x.DefaultIfIdIsNegative());
return Verifier.Verify(query.ToQueryString());
}
}
}
@@ -0,0 +1,5 @@
SELECT CASE
WHEN [e].[Id] >= 0 THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END, [e].[Id], [e].[Name]
FROM [Entity] AS [e]
@@ -0,0 +1,3 @@
SELECT [e].[Id]
FROM [Entity] AS [e]
ORDER BY [e].[Id]
@@ -0,0 +1,7 @@
namespace EntityFrameworkCore.Projectables.FunctionalTests.Generics
{
public interface IEntity
{
int Id { get; }
}
}
@@ -0,0 +1,2 @@
SELECT CAST(1 AS bit), [e].[Id], [e].[Name]
FROM [Entity] AS [e]
@@ -0,0 +1,48 @@
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 MultipleGenericsTests
{
[Projectable]
public static object? Coalesce<T1, T2>(T1? t1, T2 t2)
=> t1 != null ? t1 : t2;
[Fact]
public Task TestMultipleArguments()
{
using var context = new SampleDbContext<Entity>();
var query = context.Set<Entity>()
.Select(x => Coalesce(x.Id, x.Name));
return Verifier.Verify(query.ToQueryString());
}
[Fact]
public void MultipleInvocations()
{
using var context = new SampleDbContext<Entity>(Infrastructure.CompatibilityMode.Full);
var query1 = context.Set<Entity>()
.Select(x => Coalesce(x.Id, x.Name))
.ToQueryString();
var query2 = context.Set<Entity>()
.Select(x => Coalesce(x.Name, x.Id))
.ToQueryString();
Assert.NotEqual(query1, query2);
}
}
}
@@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression =>
(global::Foo.C @this) => 0;
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression()
{
return (global::Foo.C @this) =>
0;
}
}
}
@@ -0,0 +1,19 @@
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
using Foo;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable
{
public static class Foo_EntityExtensions_EnforceString
{
public static System.Linq.Expressions.Expression<System.Func<T, string>> Expression<T>()
where T : unmanaged
{
return (T value) =>
value.ToString();
}
}
}
@@ -9,7 +9,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_NextFoo
{
public static System.Linq.Expressions.Expression<System.Func<List<object> ,List<int?>, List<object>>> Expression =>
(List<object> input,List<int?> nullablePrimitiveArgument) => input;
public static System.Linq.Expressions.Expression<System.Func<List<object> ,List<int?>, List<object>>> Expression()
{
return (List<object> input,List<int?> nullablePrimitiveArgument) =>
input;
}
}
}
@@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression =>
(global::Foo.C @this) => @this.Bar + @this.Bar + @this.Bar;
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression()
{
return (global::Foo.C @this) =>
@this.Bar + @this.Bar + @this.Bar;
}
}
}
@@ -9,7 +9,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_EntityExtensions_GetFirstRelatedIgnoreNulls
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.EntityExtensions.Entity, global::Foo.EntityExtensions.Entity>> Expression =>
(global::Foo.EntityExtensions.Entity entity) => entity.RelatedEntities[0];
public static System.Linq.Expressions.Expression<System.Func<Entity, Entity>> Expression()
{
return (Entity entity) =>
entity.RelatedEntities[0];
}
}
}
@@ -9,7 +9,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_EntityExtensions_GetFirstRelatedIgnoreNulls
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.EntityExtensions.Entity, global::Foo.EntityExtensions.Entity>> Expression =>
(global::Foo.EntityExtensions.Entity entity) => entity != null ? (entity.RelatedEntities != null ? (entity.RelatedEntities[0]) : null) : null;
public static System.Linq.Expressions.Expression<System.Func<Entity, Entity>> Expression()
{
return (Entity entity) =>
entity != null ? (entity.RelatedEntities != null ? (entity.RelatedEntities[0]) : null) : null;
}
}
}
@@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_GetFirst
{
public static System.Linq.Expressions.Expression<System.Func<string, string>> Expression =>
(string input) => input[0].ToString();
public static System.Linq.Expressions.Expression<System.Func<string, string>> Expression()
{
return (string input) =>
input[0].ToString();
}
}
}
@@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_GetFirst
{
public static System.Linq.Expressions.Expression<System.Func<string, string>> Expression =>
(string input) => input != null ? (input[0].ToString()) : null;
public static System.Linq.Expressions.Expression<System.Func<string, string>> Expression()
{
return (string input) =>
input != null ? (input[0].ToString()) : null;
}
}
}
@@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_GetLength
{
public static System.Linq.Expressions.Expression<System.Func<string, int?>> Expression =>
(string input) => input.Length;
public static System.Linq.Expressions.Expression<System.Func<string, int?>> Expression()
{
return (string input) =>
input.Length;
}
}
}
@@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_GetLength
{
public static System.Linq.Expressions.Expression<System.Func<string, int?>> Expression =>
(string input) => input != null ? (input.Length) : null;
public static System.Linq.Expressions.Expression<System.Func<string, int?>> Expression()
{
return (string input) =>
input != null ? (input.Length) : null;
}
}
}
@@ -9,7 +9,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_EntityExtensions_GetFirstName
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.EntityExtensions.Entity, string>> Expression =>
(global::Foo.EntityExtensions.Entity entity) => entity.FullName != null ? (entity.FullName.Substring(entity.FullName != null ? (entity.FullName.IndexOf(' ') ) : null?? 0)) : null;
public static System.Linq.Expressions.Expression<System.Func<Entity, string>> Expression()
{
return (Entity entity) =>
entity.FullName != null ? (entity.FullName.Substring(entity.FullName != null ? (entity.FullName.IndexOf(' ') ) : null?? 0)) : null;
}
}
}
@@ -9,7 +9,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_NullableReferenceType
{
public static System.Linq.Expressions.Expression<System.Func<object, string>> Expression =>
(object input) => (string)input;
public static System.Linq.Expressions.Expression<System.Func<object, string>> Expression()
{
return (object input) =>
(string)input;
}
}
}
@@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_NextFoo
{
public static System.Linq.Expressions.Expression<System.Func<object ,int?, object>> Expression =>
(object unusedArgument,int? nullablePrimitiveArgument) => null;
public static System.Linq.Expressions.Expression<System.Func<object ,int?, object>> Expression()
{
return (object unusedArgument,int? nullablePrimitiveArgument) =>
null;
}
}
}
@@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_GetFirst
{
public static System.Linq.Expressions.Expression<System.Func<string, char?>> Expression =>
(string input) => input[0];
public static System.Linq.Expressions.Expression<System.Func<string, char?>> Expression()
{
return (string input) =>
input[0];
}
}
}
@@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_GetFirst
{
public static System.Linq.Expressions.Expression<System.Func<string, char?>> Expression =>
(string input) => input != null ? (input[0]) : null;
public static System.Linq.Expressions.Expression<System.Func<string, char?>> Expression()
{
return (string input) =>
input != null ? (input[0]) : null;
}
}
}
@@ -9,7 +9,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_NullableValueType
{
public static System.Linq.Expressions.Expression<System.Func<object, int?>> Expression =>
(object input) => (int?)input;
public static System.Linq.Expressions.Expression<System.Func<object, int?>> Expression()
{
return (object input) =>
(int?)input;
}
}
}
@@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C ,int ,string ,object, int>> Expression =>
(global::Foo.C @this,int a,string b,object d) => a;
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C ,int ,string ,object, int>> Expression()
{
return (global::Foo.C @this,int a,string b,object d) =>
a;
}
}
}
@@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C ,int, int>> Expression =>
(global::Foo.C @this,int i) => i;
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C ,int, int>> Expression()
{
return (global::Foo.C @this,int i) =>
i;
}
}
}
@@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression =>
(global::Foo.C @this) => @this.Bar();
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression()
{
return (global::Foo.C @this) =>
@this.Bar();
}
}
}
@@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression =>
(global::Foo.C @this) => @this.Bar;
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression()
{
return (global::Foo.C @this) =>
@this.Bar;
}
}
}
@@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.D, int>> Expression =>
(global::Foo.D d) => 1;
public static System.Linq.Expressions.Expression<System.Func<D, int>> Expression()
{
return (D d) =>
1;
}
}
}
@@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo
{
public static System.Linq.Expressions.Expression<System.Func<int, int>> Expression =>
(int i) => i;
public static System.Linq.Expressions.Expression<System.Func<int, int>> Expression()
{
return (int i) =>
i;
}
}
}
@@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo1
{
public static System.Linq.Expressions.Expression<System.Func<int, int>> Expression =>
(int i) => i;
public static System.Linq.Expressions.Expression<System.Func<int, int>> Expression()
{
return (int i) =>
i;
}
}
}
@@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo1
{
public static System.Linq.Expressions.Expression<System.Func<object, object>> Expression =>
(object i) => i.Foo1();
public static System.Linq.Expressions.Expression<System.Func<object, object>> Expression()
{
return (object i) =>
i.Foo1();
}
}
}
@@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, global::Foo.D>> Expression =>
(global::Foo.C @this) => @this.Dees.First();
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, D>> Expression()
{
return (global::Foo.C @this) =>
@this.Dees.First();
}
}
}
@@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_D_Foo
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C.D, int>> Expression =>
(global::Foo.C.D @this) => @this.Bar + 1;
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C.D, int>> Expression()
{
return (global::Foo.C.D @this) =>
@this.Bar + 1;
}
}
}
@@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression =>
(global::Foo.C @this) => @this.Bar + 1;
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression()
{
return (global::Foo.C @this) =>
@this.Bar + 1;
}
}
}
@@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression =>
(global::Foo.C @this) => 1;
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression()
{
return (global::Foo.C @this) =>
1;
}
}
}
@@ -7,7 +7,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression =>
(global::Foo.C @this) => 1;
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression()
{
return (global::Foo.C @this) =>
1;
}
}
}
@@ -8,7 +8,10 @@ namespace EntityFrameworkCore.Projectables.Generated
{
public static class Foo_C_Foo
{
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression =>
(global::Foo.C @this) => @this.Dees.OfType<global::Foo.D>().Count();
public static System.Linq.Expressions.Expression<System.Func<global::Foo.C, int>> Expression()
{
return (global::Foo.C @this) =>
@this.Dees.OfType<global::Foo.D>().Count();
}
}
}
@@ -834,6 +834,39 @@ namespace Foo {
return Verifier.Verify(result.GeneratedTrees[0].ToString());
}
[Fact]
public Task GenericMethods_AreRewritten()
{
var compilation = CreateCompilation(@"
using System;
using System.Linq;
using System.Collections.Generic;
using EntityFrameworkCore.Projectables;
namespace Foo {
public static class EntityExtensions
{
public record Entity
{
public int Id { get; set; }
public string? FullName { get; set; }
}
[Projectable]
public static string EnforceString<T>(T value) where T : unmanaged
=> value.ToString();
}
}
");
var result = RunGenerator(compilation);
Assert.Empty(result.Diagnostics);
Assert.Single(result.GeneratedTrees);
return Verifier.Verify(result.GeneratedTrees[0].ToString());
}
#region Helpers
Compilation CreateCompilation(string source, bool expectedToCompile = true)