Last active
May 28, 2017 14:44
-
-
Save giuliohome/cba2ddeef14226a0997d8daeb0a816a7 to your computer and use it in GitHub Desktop.
nested runtime coercion for a Nullable double https://stackoverflow.com/questions/44199961/nested-runtime-coercion-for-a-nullable-double/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://dotnetfiddle.net/sjSjeS | |
open System | |
open System.Data | |
open System.Xml | |
open Microsoft.FSharp.Linq | |
type RowReader(reader:DataRow) = | |
member private x.Reader = reader | |
static member (?) (x:RowReader, name:string) : 'R = | |
x.Reader.[name] :?> 'R | |
printfn "Hello World" | |
let z = "name" | |
let table = new DataTable() | |
let col = new DataColumn() | |
col.ColumnName <- z | |
col.DataType <- System.Type.GetType("System.Double") | |
table.Columns.Add col | |
let x = table.NewRow() | |
let xx = RowReader(x) | |
x.[z] <- 7. | |
printf "check %f" (x.[z] :?> double) | |
let comm = 3. | |
let y = if x.IsNull(z) then Nullable() else xx?name ?* comm | |
printfn "\ny: %f" y.Value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated fiddle with default