Flexpressions v1.0 - Fluent API for Linq Expressions - Released
-
I've been pulling hours after work to put together a fluent API for generating Linq Expressions. I've finally wrapped up all coding and unit testing (100% coverage - booya). It basically brings Expressions up one level to something closer to C#, rather than a huge block of intermediate objects. I'm planning on starting the CodeProject article tomorrow, but if you're interested in an advanced screening - check it out here[^]. Here's an example of what it looks like in action to create a summation function:
Expression<Func<int[], int>> expression = Flexpression<Func<int[], int>>
.Create(false, "input")
.If<int[]>(input => input == null)
.Throw(() => new ArgumentNullException("input"))
.EndIf()
.If<int[]>(input => input.Length == 0)
.Throw(() => new ArgumentException("The array must contain elements.", "input"))
.EndIf()
.Declare<int>("sum")
.Set<int>("sum", () => 0)
.Foreach<int, int[], int[]>("x", input => input)
.Set<int, int, int>("sum", (sum, x) => sum + x)
.End()
.Return<int, int>(sum => sum)
.CreateLambda(); -
I've been pulling hours after work to put together a fluent API for generating Linq Expressions. I've finally wrapped up all coding and unit testing (100% coverage - booya). It basically brings Expressions up one level to something closer to C#, rather than a huge block of intermediate objects. I'm planning on starting the CodeProject article tomorrow, but if you're interested in an advanced screening - check it out here[^]. Here's an example of what it looks like in action to create a summation function:
Expression<Func<int[], int>> expression = Flexpression<Func<int[], int>>
.Create(false, "input")
.If<int[]>(input => input == null)
.Throw(() => new ArgumentNullException("input"))
.EndIf()
.If<int[]>(input => input.Length == 0)
.Throw(() => new ArgumentException("The array must contain elements.", "input"))
.EndIf()
.Declare<int>("sum")
.Set<int>("sum", () => 0)
.Foreach<int, int[], int[]>("x", input => input)
.Set<int, int, int>("sum", (sum, x) => sum + x)
.End()
.Return<int, int>(sum => sum)
.CreateLambda();Cool! :thumbsup:
I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking