我正在尝试statically type
arecord field
然后返回它field
(确切地说是唯一的项目)。
所以它看起来像这样:
type Item = {Id:int; Name:string}
with
member this.field fieldName =
let info = getInfo fieldName
this
|> Seq.map (fun record -> FSharpValue.GetRecordField info)
|> Seq.distinct |> Seq.sort |> Array.ofSeq
let item = {Id = 1; Name = "First"}
let ids = item.field Item.Id
我发现了 Tomas Petricek关于这个主题的这篇旧文章,但我认为会有更好的方法,F# 3.0
它也可以扩展到VB
.