Question

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.

Était-ce utile?

La solution 2

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

Autres conseils

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}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top