Thursday, December 1, 2011

F# ≥ C# (Extend type by properties)

In previous post, the type extension give me a lead to today's blog. C# programmer has been asking for "extension property" since introducing "extension method". Do not wait for C# any more, F# already got the feature:

type SomeClass1(x: int, y: float) =
   new() = SomeClass1(0, 0.)
type SomeClass1 with
    member this.PropertyA
        with get() = "aa"
        and set (v) = ....

this feature is not just for F#. You can invoke this PropertyA from C# as well. Is F# more convenient? :)

No comments: