I need to specify, that my member property will return something like dynamic? in C#. Is possible use dynamic data type in F#?
type Data =
| Text of string
| Number of string
| Date of string
with
member x.Value
with get() : dynamic option =
match x with
| Text(value) ->
if value.Length > 0 then Some(value) else None
| Number(value) ->
let (success, number) = Decimal.TryParse value
if (success) then Some(number) else None
| Date(value) ->
let (success, date) = DateTime.TryParse value
if (success) then Some(date) else None
This code cannot be compiled, because return type is determined as string option from Text case. Keyword dynamic is unknown in F#. Any ideas?
Try to make this datatype:
type ThreeWay = S of string | N of Decimal | D of DateTimeor, use the
System.Objecttype:To get the value: