@@ -3,6 +3,7 @@ open System.Runtime.CompilerServices
33open System
44open System.Collections .Generic
55open FSharpPlus
6+ open FSharpPlus.Internals
67module internal Internals =
78 module Result =
89 /// Wraps a function, encapsulates any exception thrown within to a Result
@@ -14,8 +15,10 @@ module internal Internals=
1415 /// Stores the cast value in Ok if successful, otherwise stores the exception in Error
1516 let inline cast ( o : obj ) = protect unbox o
1617
18+ let inline tupleToOption x = match x with true , value -> Some value | _ -> None
1719
1820open Internals
21+ open System.Globalization
1922
2023[<Extension>]
2124type Options =
@@ -149,23 +152,19 @@ type Options =
149152
150153 static member SomeUnit = Some()
151154
152- static member ParseInt s : int32 option = tryParse s
155+ type NumberParser ( numberstyles : NumberStyles , cultureInfo : CultureInfo )=
156+ new ()= NumberParser( NumberStyles.Any, CultureInfo.InvariantCulture)
157+ member __.ParseDateTimeOffset s : DateTimeOffset option = tryParse s
158+ member __.TryParseDecimal ( x : string )= Decimal.TryParse ( x, numberstyles, cultureInfo) |> tupleToOption : option< decimal>
159+ member __.TryParseFloat ( x : string )= Single.TryParse ( x, numberstyles, cultureInfo) |> tupleToOption : option< float32>
160+ member __.TryParseDouble ( x : string )= Double.TryParse ( x, numberstyles, cultureInfo) |> tupleToOption : option< float>
161+ member __.TryParseUint16 ( x : string )= UInt16.TryParse ( x, numberstyles, cultureInfo) |> tupleToOption : option< uint16>
162+ member __.TryParseUint32 ( x : string )= UInt32.TryParse ( x, numberstyles, cultureInfo) |> tupleToOption : option< uint32>
163+ member __.TryParseUint64 ( x : string )= UInt64.TryParse ( x, numberstyles, cultureInfo) |> tupleToOption : option< uint64>
164+ member __.TryParseInt16 ( x : string )= Int16.TryParse ( x, numberstyles, cultureInfo) |> tupleToOption : option< int16>
165+ member __.TryParseInt ( x : string )= Int32.TryParse ( x, numberstyles, cultureInfo) |> tupleToOption : option< int>
166+ member __.TryParseInt64 ( x : string )= Int64.TryParse ( x, numberstyles, cultureInfo) |> tupleToOption : option< int64>
153167
154- static member ParseDecimal s : Decimal option = tryParse s
155-
156- static member ParseDouble s : Double option = tryParse s
157-
158- static member ParseFloat s : Single option = tryParse s
159-
160- static member ParseInt16 s : Int16 option = tryParse s
161-
162- static member ParseInt64 s : Int64 option = tryParse s
163-
164- static member ParseByte s : byte option = tryParse s
165-
166- static member ParseDateTime s : DateTime option = tryParse s
167-
168- static member ParseDateTimeOffset s : DateTimeOffset option = tryParse s
169168
170169[<Extension>]
171170type Choices =
0 commit comments