The JValue class does implement IConvertible, but in Fluid.Create, when System.Type.GetTypeCode() is called with JValue type in the argument, it returns TypeCode.Object. And under this case, it was going to the IFormattable case and being converted to string regardless of the underlying data type. But when JValue is cast to IConvertible and then the GetTypeCode() method is called on the object, it does return the correct type code corresponding to the underlying value.
So to resolve the issue #609, I have moved the IConvertible case above IFormattable, and also changed its implementation to extract the underlying value and call the Create method again with that value. To prevent any infinite recursion, I have explicitly handled the TypeCode.Object case by returning the string value for it.
fixes #609
The
JValue
class does implement IConvertible, but inFluid.Create
, whenSystem.Type.GetTypeCode()
is called with JValue type in the argument, it returnsTypeCode.Object
. And under this case, it was going to theIFormattable
case and being converted to string regardless of the underlying data type. But whenJValue
is cast toIConvertible
and then theGetTypeCode()
method is called on the object, it does return the correct type code corresponding to the underlying value.So to resolve the issue #609, I have moved the
IConvertible
case aboveIFormattable
, and also changed its implementation to extract the underlying value and call the Create method again with that value. To prevent any infinite recursion, I have explicitly handled theTypeCode.Object
case by returning the string value for it.