Don't rewrite cast expressions

This commit is contained in:
Koen Bekkenutte
2022-01-23 00:40:33 +08:00
parent 7def9c21f0
commit ba5f4972de
4 changed files with 54 additions and 16 deletions
@@ -0,0 +1,15 @@
using EntityFrameworkCore.Projectables;
using Projectables.Repro;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable
{
public static class Projectables_Repro_SomeExtensions_AsSomeResult
{
public static System.Linq.Expressions.Expression<System.Func<global::Projectables.Repro.SomeEntity, string>> Expression()
{
return (global::Projectables.Repro.SomeEntity e) =>
((global::Projectables.Repro.SuperEntity)e).Superpower;
}
}
}
@@ -1,14 +0,0 @@
using EntityFrameworkCore.Projectables;
namespace EntityFrameworkCore.Projectables.Generated
#nullable disable
{
public static class _SomeExtensions_Test
{
public static System.Linq.Expressions.Expression<System.Func<global::SomeFlag, bool>> Expression()
{
return (global::SomeFlag f) =>
f == global::SomeFlag.Foo;
}
}
}
@@ -1045,6 +1045,39 @@ public static class SomeExtensions
return Verifier.Verify(result.GeneratedTrees[0].ToString());
}
[Fact]
public Task Cast()
{
var compilation = CreateCompilation(@"
using EntityFrameworkCore.Projectables;
namespace Projectables.Repro;
public class SuperEntity : SomeEntity
{
public string Superpower { get; set; }
}
public class SomeEntity
{
public int Id { get; set; }
}
public static class SomeExtensions
{
[Projectable]
public static string AsSomeResult(this SomeEntity e) => ((SuperEntity)e).Superpower;
}
");
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)