type MyType =
inherit DotNetType
[<DefaultValue>] static val mutable private myStatic : int
new () = { inherit DotNetType() }
new (someArg:string) = { inherit DotNetType(someArg) }
This uses a primary constructor but I think it still accomplishes what you were looking for
type DotNetType =
val private _x:string
new(x:string) = { _x = x }
new() = DotNetType("")
type MyType private (x:obj) =
inherit DotNetType()
static let mutable initialized = false
static let mutable config = 0
static member private Init() =
if initialized = true then () else
initialized <- true
config <- config + 50 // add to self to see if called
static member SConfig = string config
member __.IConfig = string config
new() =
MyType.Init(); MyType obj
new(msg:string,cnt:int) =
MyType.Init();
printfn "Secondary ConstructorI #%i" cnt
MyType 45
new(msg:string,cnt:float) =
MyType.Init();
printfn "Secondary ConstructorF #%A\n%s" cnt msg
MyType ""
member val InstProp = "allo" with get, set
;;
printfn "Before First Construction - %s" MyType.SConfig
let x1 = MyType("greetings",20.0,InstProp = " x_1 ")
printfn "After First Construction - %s" MyType.SConfig
printfn "Static config via {x1} - %s\n" x1.IConfig
printfn "Before Second Construction - %s" MyType.SConfig
let x2 = MyType()
x2.InstProp <- " x_2 "
printfn "After Second Construction - %s" MyType.SConfig
printfn "Static config via {x2} - %s\n" x1.IConfig
printfn "Built {%s} & {%s} but stayed at - %s"
x1.InstProp x2.InstProp MyType.SConfig
The FSI Output is -
type DotNetType =
class
new : unit -> DotNetType
new : x:string -> DotNetType
val private _x: string
end
type MyType =
class
inherit DotNetType
new : unit -> MyType
private new : x:obj -> MyType
new : msg:string * cnt:int -> MyType
new : msg:string * cnt:float -> MyType
member IConfig : string
member InstProp : string
member InstProp : string with set
static member private Init : unit -> unit
static member SConfig : string
end
> Before First Construction - 0
Secondary ConstructorF #20.0
greetings
After First Construction - 50
Static config via {x1} - 50
Before Second Construction - 50
After Second Construction - 50
Static config via {x2} - 50
Built { x_1 } & { x_2 } but stayed at - 50
val x1 : MyType
val x2 : MyType
val it : unit = ()
>