Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Flexpressions v1.0 - Fluent API for Linq Expressions - Released

Flexpressions v1.0 - Fluent API for Linq Expressions - Released

Scheduled Pinned Locked Moved The Lounge
csharplinqcomdata-structurestesting
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andrew Rissing
    wrote on last edited by
    #1

    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();

    B 1 Reply Last reply
    0
    • A Andrew Rissing

      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();

      B Offline
      B Offline
      Brisingr Aerowing
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups