axelheer / nein-linq

NeinLinq provides helpful extensions for using LINQ providers such as Entity Framework that support only a minor subset of .NET functions, reusing functions, rewriting queries, even making them null-safe, and building dynamic queries using translatable predicates and selectors.
MIT License
521 stars 22 forks source link

How about an implicit cast to `CachedExpression<X>` from `Expression<X>`? #32

Closed space-alien closed 2 years ago

space-alien commented 2 years ago

So that

private static CachedExpression<Func<Character, bool>> IsVeryCleverExpr { get; }
    = new CachedExpression(c => c.Cleverness > 90);

Could become

private static CachedExpression<Func<Character, bool>> IsVeryCleverExpr { get; }
    = c => c.Cleverness > 90;
axelheer commented 2 years ago

Yeah, that would look nice. Do you want to send a PR?

space-alien commented 2 years ago

With pleasure!

space-alien commented 2 years ago

I see that the implicit cast from Expression<X> already exists, but the usage I propose is impossible, isn't it, because it would require the compiler to chain two implicit casts?

axelheer commented 2 years ago

Ahh, makes sense. Maybe I already tried it back then... 😳

space-alien commented 2 years ago

It was a fun little 30-minute rabbit hole for a Friday afternoon! 😅