accessing dynamic objects in F#

吃可爱长大的小学妹 提交于 2019-12-24 00:03:18

问题


I'm parameterizing some linq queries, and ended up using dynamic linq. Initially I had some trouble extracting the data from the dynamic objects it created but I managed to extract it using FSharp. InteropDynamic, regarding a better way to parameterize linq queries I plan to post another question. My question is .

  1. Is this the best way to access dynamic linq and/or dynamic objects (memory and speed wise?).
  2. When I first use it FSI gives me a message.

    Binding session to '..\..\packages\Dynamitey.1.0.2.0\lib\net40\Dynamitey.dll'...

What is this exactly?

Simplified code:

#if INTERACTIVE
#r "System.Data.Linq.dll"
#r @"..\packages\System.Linq.Dynamic.1.0.6\lib\net4\System.Linq.Dynamic.dll"
#r @"..\packages\FSharp.Interop.Dynamic.3.0.0.0\lib\portable-net45+sl50+win\FSharp.Interop.Dynamic.dll"
#r @"..\packages\Dynamitey.1.0.2.0\lib\net40\Dynamitey.dll"
#endif    

open System.Linq
open System.Linq.Dynamic
open FSharp.Interop.Dynamic

type Rec1 = { 
    City:string
    Country:string
    Zip:int
    }

let x =  [{City="London";Country="UK";Zip=1029};{City="Glasgow";Country="UK";Zip=30921};
               {City="London";Country="USA";Zip=90210}] 
let y = x.Where(fun x -> x.City ="London").Select("new(City,Zip)")
[for xx in y -> (xx?City:string),(xx?Zip:int)]

This will give me: val it : (string * int) list = [("London", 1029); ("London", 90210)] as expected.

This is a good overview of using dynamic objects from F#: F# dynamic object access

来源:https://stackoverflow.com/questions/36539639/accessing-dynamic-objects-in-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!