Вопрос

I need a few public properties, in C# I will do this way.

public VendorOrderService { get; set; }

What is the shortest (correct/idiomatic) syntax for such properties in F#?

member val VendorService = Unchecked.defaultof<VendorOrderService> with get, set

P.S. I do understand that public properties are not super idiomatic for F#. But this code is working in larger .NET project, so such properties are obligatory.

Это было полезно?

Решение 2

type Foo() =
     member val Text : string = null with get, set

Другие советы

First of all in C# you should write type, like this

public string VendorOrderService { get; set; }

In F# 3.0 you can use val keyword (just like you are):

type MyType() = 
    member val VendorOrderService = "" with get, set

or use [CLIMutable] attribute:

[<CLIMutable>]
type MyType = { VendorOrderService:string}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top