FileHelpers 类型中的字段顺序
我正在使用 Filehelpers 读取一个简单的 CSV 文件 - 该文件只是一个键值对。 (string, int64)
我为此编写的 f# 类型是:
type MapVal (key:string, value:int64) =
new()= MapVal("",0L)
member x.Key = key
member x.Value = value
我在这里遗漏了一些基本内容,但 FileHelpers 始终假定字段的顺序与我指定的顺序相反 - 如 Value、Key 中所示。
let dfe = new DelimitedFileEngine(typeof<MapVal>)
let recs = dfe.ReadFile(@"D:\e.dat")
recs |> Seq.length
我在这里缺少什么?
I'm reading a simple CSV file with Filehelpers - the file is just a key, value pair. (string, int64)
The f# type I've written for this is:
type MapVal (key:string, value:int64) =
new()= MapVal("",0L)
member x.Key = key
member x.Value = value
I'm missing something elementary here, but FileHelpers always assumes the order of fields to be the reverse of what I've specified - as in Value, Key.
let dfe = new DelimitedFileEngine(typeof<MapVal>)
let recs = dfe.ReadFile(@"D:\e.dat")
recs |> Seq.length
What am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
主构造函数参数的顺序不一定决定字段在类型中出现的顺序(事实上,根据参数的使用方式,它们甚至可能不会导致生成字段)。在我看来,FileHelpers 没有提供使用属性而不是字段的方法,这一事实是不幸的。如果您想更好地控制类的物理布局,则需要显式声明字段:
The order of primary constructor parameters doesn't necessarily determine the order that fields occur within a type (in fact, depending on how the parameters are used, they may not even result in a field being generated). The fact that FileHelpers doesn't provide a way to use properties instead of fields is unforunate, in my opinion. If you want better control over the physical layout of the class, you'll need to declare the fields explicitly:
该库在声明中使用字段的顺序,但看起来与 F# 单词不同,在该库的最后一个稳定版本中,您可以使用 [FieldOrder(1)] 属性来提供字段的顺序。
http://teamcity.codebetter.com /viewLog.html?buildId=lastSuccessful&buildTypeId=bt66&tab=artifacts&guest=1
干杯
The library uses the order of the field in the declaration, but looks like that F# words different, in the last the last stable version of the library you can use the [FieldOrder(1)] attribute to provide the order of the fields.
http://teamcity.codebetter.com/viewLog.html?buildId=lastSuccessful&buildTypeId=bt66&tab=artifacts&guest=1
Cheers