Last active
August 29, 2015 14:17
-
-
Save rojepp/61261f5757cb2e0a2eb3 to your computer and use it in GitHub Desktop.
toNullable
This file contains hidden or 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
let toNullable x : System.Nullable<_> = | |
match x with | |
| Some v -> System.Nullable<_>(v) | |
| _ -> System.Nullable() | |
// Extension for use from F# | |
type Option<'t> with | |
member this.ToNullable () = | |
toNullable (box this |> unbox) | |
// Extension for use from C# | |
[<System.Runtime.CompilerServices.Extension>] | |
module ExtensionMethods = | |
[<System.Runtime.CompilerServices.Extension>] | |
let ToNullable(o : Option<'t>) : Nullable<'t> = toNullable (box o |> unbox) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment