对不起,如果这是基本的,但我仍然在 F# 周围环绕我的头。
我想做这个:
type Person(user:User) as this =
member val Name = "" with get, set
user.UserId <- this.Name
但这给了我错误Unexpected identifier in member definition
。
这编译:
type Person(user:User) as this =
do
user.UserId <- this.Name
member val Name = "" with get, set
但是InvalidOperationException
在运行时给了我一个。
我已经解决了这个问题:
type Person(user:User) =
member val Name = "" with get, set
member this.Setup() =
user.UserId <- this.Name
但我不喜欢person.Setup()
每次都打电话。
执行此操作的最佳 F-Sharpy 方法是什么?