fsprojects / FSharp.Configuration

The FSharp.Configuration project contains type providers for the configuration of .NET projects.
http://fsprojects.github.io/FSharp.Configuration/
Other
114 stars 63 forks source link

The app setting value 012 is parsed as integer and becomes 12 #95

Open devtxdotnet opened 8 years ago

devtxdotnet commented 8 years ago

When an app setting value has a leading zero "0" for examle "CatalogId" "012" the type AppSettings has a property "CatalogId" of type int and the value 12.

<appSettings>
    <add key="CatalogId" value="012" />
</appSettings>

It should be instead of type string so that the leading zero is not lost, because 12 is not the same as 012.

Actually I have to insert a leading character for example "z012" as a value to force "CatalogId" to be of type string.

Robert Niemann

vasily-kirichenko commented 8 years ago

We infer 012 as int because it can be parsed as int without errors. Could you suggest a way to say the TP that 012 is a string, not an integer?

devtxdotnet commented 8 years ago

After parsing any string to a number these number could be converted back to a string and when these string is not equal to the parsed one the parsing should fail. But I have seen that these behavior will clash with the actual behavior for both integer and floating-point number parsing. And I do not know if the current behavior is intended.

vasily-kirichenko commented 8 years ago

We need to look at how types are inferred in FSharp.Data project.

devtxdotnet commented 8 years ago

They do for example Int32.TryParse(TextConversions.RemoveAdorners text, NumberStyles.Integer, cultureInfo) but their domain is different I would say. In an app.setting file I would expect that any value should be used as it is because they are configurations. In the context of big data analysis there are fuzzy values. I would expect that my configuration values are not changed at all. There should be no fuzziness when configuration values are parsed. What do you think about that?

vasily-kirichenko commented 8 years ago

What about a static parameter, which would force the TP to make all properties to be of type string?

Like this:

type T = AppSettings<"app.config", InferTypes = false>
devtxdotnet commented 8 years ago

But what is then the benefit of the type provider? In that case I could still use the configuration manager.

vasily-kirichenko commented 8 years ago

I don't know :) I've not used app.configs for years (I've used yaml instead).