Skip to content

Instantly share code, notes, and snippets.

@Thorium
Last active November 27, 2015 13:44
Show Gist options
  • Save Thorium/52fcebbb5109fd59c257 to your computer and use it in GitHub Desktop.
Save Thorium/52fcebbb5109fd59c257 to your computer and use it in GitHub Desktop.
F# lambda (quotation) to C# Expression<Func<_>> or Expression<Action<_>>
open Microsoft.FSharp.Linq.RuntimeHelpers
open System
open System.Linq.Expressions
module Lambda =
let toExpression (``f# lambda`` : Quotations.Expr<'a>) =
``f# lambda``
|> LeafExpressionConverter.QuotationToExpression
|> unbox<Expression<'a>>
let test =
<@ Func<int, int>(fun i -> i + 5) @> |> Lambda.toExpression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment