我需要一些公共属性,在c#中我将这样做。
public VendorOrderService { get; set; }
在f#中这样的属性最短的(正确的/惯用的)语法是什么?member val VendorService = Unchecked.defaultof<VendorOrderService> with get, set
注:我确实理解公共属性对于f#来说并不是超级习惯用法。但是这些代码是在更大的。net项目中工作的,所以这些属性是必须的。
首先在c#中你应该写type,像这样
public string VendorOrderService { get; set; }
在f# 3.0中,你可以使用val关键字(就像你一样):
type MyType() =
member val VendorOrderService = "" with get, set
或使用[CLIMutable]属性:
[<CLIMutable>]
type MyType = { VendorOrderService:string}
type Foo() =
member val Text : string = null with get, set