如何使用F#为属性声明私有setter

Sco*_*rod 4 f#

在C#中,我们可以声明属性的私有setter.如何使用F#完成此操作?

具体来说,我怎样才能确保只能在类中更改属性的状态?

例如,我们如何将FirstName setter属性声明为private,就像在C#中一样?

public string FirstName { get; private set; }
Run Code Online (Sandbox Code Playgroud)
type SomeViewModel() =
    inherit ViewModel()
    let mutable firstName = ""
    let mutable lastName = ""

    member this.FirstName
        with get() = firstName 
        and set(value) =
            firstName <- value
            base.notifyPropertyChanged(<@ this.FirstName @>)

    member this.LastName
        with get() = lastName 
        and set(value) =
            lastName <- value
            base.notifyPropertyChanged(<@ this.LastName @>)

    member this.GetFullName() = 
        sprintf "%s %s" (this.FirstName) (this.LastName)
Run Code Online (Sandbox Code Playgroud)

ild*_*arn 10

member this.FirstName
    with get() = firstName 
    and private set(value) =
        firstName <- value
        base.notifyPropertyChanged(<@ this.FirstName @>)
Run Code Online (Sandbox Code Playgroud)

这直接在MSDN F#文档中显示.