ExpressionToCode
ExpressionToCode copied to clipboard
You also know https://github.com/jbevain/mono.linq.expressions
There exists also https://github.com/jbevain/mono.linq.expressions
Maybe it will useful for you?
The generated code appears to be fairly hard to use; e.g.
var x=1;
var a=2;
var b=3;
DumpExpr(() => x - (a - b) + x * (a + b));
prints () => x - (a - b) + x * (a + b)
when implemented with ExpressionToCode, but when using Mono.Linq.Expressions it prints...
int ()
{
return (UserQuery+<>c__DisplayClass0_0.x - (UserQuery+<>c__DisplayClass0_0.a - UserQuery+<>c__DisplayClass0_0.b)) + (UserQuery+<>c__DisplayClass0_0.x * (UserQuery+<>c__DisplayClass0_0.a + UserQuery+<>c__DisplayClass0_0.b));
}
Another example:
DumpExpr(() => Enumerable.Range(2, 1000).Where(n => !Enumerable.Range(2, n - 2).Any(p => n % p == 0)).Select(prime => $"Number {prime} is prime!"));
results in
() => Enumerable.Range(2, 1000).Where(n => !Enumerable.Range(2, n - 2).Any(p => n % p == 0)).Select(prime => $"Number {prime} is prime!")
vs.
IEnumerable<string> ()
{
return Enumerable.Select<int, string>(Enumerable.Where<int>(Enumerable.Range(2, 1000), (int n) =>
{
return !Enumerable.Any<int>(Enumerable.Range(2, n - 2), (int p) =>
{
return (n % p) == 0;
});
}), (int prime) =>
{
return string.Format("Number {0} is prime!", (object)prime);
});
}
ExpressionToCode also intrinsically needs more detail than merely a string-output from an expression, because it tries to annotate sub-expressions with values. That may be possible with Mono.Linq.Expressions, but it isn't at first glance at any rate.
I like the inliner (is it an inliner? I'm thinking of Combine
); and the fluent API is a nice livability enhancement. A combination of the two libraries might make sense; but it would be quite the undertaking (and I wouldn't want to do that unless the maintainers of Mono.Linq.Expressions want that too ;-))
Only wanted to let you know. Didn't know if you heard of it. Don't think @jbevain does maintain it very much
I hadn't, and thanks for the heads up! It's always useful to have those kind of pointers for future changes 👍 .