我正在使用 .Net 测试一些 redis,我已经阅读了本教程 http://www.d80.co.uk/post/2011/05/12/Redis-Tutorial-with-ServiceStackRedis.aspx 并遵循使用 c# 并完美运行,现在当我尝试将其转换为 f# 时,我有一个奇怪的行为,首先我创建了一个简单的 f# 类(使用类型也不起作用,但这是预期的)...基本上类是这样的:
//I ve used [<Class>] to
type Video (id : int, title : string , image : string , url : string) =
member this.Id = id
member this.Title = title
member this.Image = image
member this.Url = url
当我运行代码时,我的数据库保存一个空数据,如果我在我的 f# 代码中使用 c# 类,那么我确定问题出在 f# 类上......如何解决这个问题而不依赖我的 f# 代码中的 c# 代码
谢谢!!!
最佳答案
根据您的教程,您似乎希望 F# Video 类充满 getter 和 setter 属性,而不是像现在这样只有带有 getter 的构造函数(它是一个类,您可以通过运行来验证通过 FSI)。
您可以使用充满可变字段的记录类型(它被编译为充满公共(public) getter 和 setter 的类类型)来实现此目的:
type Video = {
mutable Id : int
mutable Title : string
mutable Image : byte[]
mutable Url : string
}
关于f# - 使用带有 redis 服务堆栈库的 f# 类的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10004740/