ServiceStack/ServiceStack.Text — pull request #428 by scottmcarthur (2014-08-14 10:18:37+00:00)
Title: Number parsing

When using these options:

JsConfig.TryToParsePrimitiveTypeValues = true;
JsConfig.TryToParseNumericType = true;

The whole numbers i.e. integer types are returned in order of range ascending. Meaning a value of `123` will be returned as a `byte`. However it may be preferable for the user if this number was `Int32`, which is also capable of representing the value. Similarly a `float`'s `TryParse` method will accept a `decimal` number, and simply lose the precision. As would `double`'s `TryParse` method, which makes the current implementation restricting depending on the number ranges being used.

This change adds the ability to specify a preference order to test whole numbers, and a preference type for non-whole numbers.

This does not break existing functionality, because the default preference is to parse whole numbers by range ascending i.e. `byte`, `sbyte`, `Int16`, `UInt16`, `Int32`, `UInt32`, `Int64`, `UInt64`. And the default non-whole number type is still `decimal`.

- Adds the ability to specify the type to cast non-whole numbers as, e.g
`decimal` | `float` | `double`.

Usage: `JsConfig.ParseNumericNonWholeNumberAsType = typeof(float)`

- Adds the ability to specify the preference to cast whole numbers when
parsing numbers, e.g. use `Int32` before trying `sbyte` etc.

Usage: `JsConfig.ParseNumericWholeNumberAsTypePreference = new[] { typeof(Int32), typeof(Int64) }`