8 people like it.

Define a static property for F# class

it's quite easy to define a modifiable static property in C# , but in F#,a defined static filed is required first when the class want to define a static property.

1: 
2: 
3: 
4: 
5: 
6: 
7: 
type StacitMemberCls() = 
    //A static filed should be defined first
    static let mutable staticFiled = ""  
      
    static member StaticProp
        with get() = staticFiled
        and set(v) = staticFiled <- v
Multiple items
type StacitMemberCls =
  new : unit -> StacitMemberCls
  static member StaticProp : string
  static member StaticProp : string with set

Full name: Script.StacitMemberCls

--------------------
new : unit -> StacitMemberCls
val mutable staticFiled : string
static member StacitMemberCls.StaticProp : string with set

Full name: Script.StacitMemberCls.StaticProp
val set : elements:seq<'T> -> Set<'T> (requires comparison)

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.set
val v : string
Raw view Test code New version

More information

Link:http://fssnip.net/em
Posted:11 years ago
Author:ZackZhou
Tags: static property; f#