Skip to content

Instantly share code, notes, and snippets.

@braden
Created July 30, 2013 21:50
Show Gist options
  • Save braden/6117331 to your computer and use it in GitHub Desktop.
Save braden/6117331 to your computer and use it in GitHub Desktop.
Mongo property binder
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
open Microsoft.FSharp.Quotations.DerivedPatterns
let prop (expr:Quotations.Expr) =
match expr with
| Lambda(_, PropertyGet(_, prop, _)) ->
match prop.GetCustomAttributes(typeof<BsonElementAttribute>, true) with
| [| attr |] -> (attr :?> BsonElementAttribute).ElementName
| _ -> prop.Name
| _ -> failwith "Expected: <@ fun x -> x.Property @>"
type Record = {
[<BsonElement("f")>]Foo: string
Bar: string
}
prop <@ fun x -> x.Foo @>
prop <@ fun x -> x.Bar @>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment