Skip to content

Instantly share code, notes, and snippets.

@rojepp
Last active August 29, 2015 14:17
Show Gist options
  • Save rojepp/61261f5757cb2e0a2eb3 to your computer and use it in GitHub Desktop.
Save rojepp/61261f5757cb2e0a2eb3 to your computer and use it in GitHub Desktop.
toNullable
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