我跟着parse CSV using F# and filehelpers的鏈接。有編譯器錯誤下面的代碼"The record class oneRow need a constructor with no args (public or private)"
F#類的構造函數沒有參數---使用fhelp的filehelpers出錯#
[<DelimitedRecord(",")>]
type oneRow=
class
[<FieldConverter(ConverterKind.Date, "M/d/yyyy")>]
val date: DateTime
val value: bool
end
let engine = new FileHelperEngine(typeof<oneRow>)
let tmp = engine.ReadFile("test.csv")
編輯 的解決方案看起來比C#版本相當冗長。我需要添加()
,mutable
和[<DefaultValue>]
type oneRow() =
class
[<FieldConverter(ConverterKind.Date, "M/d/yyyy")>]
[<DefaultValue>]
val mutable date: DateTime
[<DefaultValue>]
val mutable value: bool
end
但類似的代碼在C#工程沒有指定一個構造函數。任何人都可以幫我修復F#代碼嗎?謝謝。
爲了使它不那麼詳細,你可以省略`class`和`結束`使用F#light語法(這是目前的默認設置)。還要注意,在F#中,不變性是默認的,所以你必須走出自己的方式來製作可變類型。 – 2011-02-11 16:43:08