FSharp.Configuration icon indicating copy to clipboard operation
FSharp.Configuration copied to clipboard

Is there a way to prevent certain conversions?

Open rkosafo opened this issue 8 years ago • 4 comments

Values likes 001, 1234, etc in my configuration ends up automatically as TimeSpan. Is there a way to prevent this? I tried quoting them but it made no difference.

rkosafo avatar Jun 02 '17 10:06 rkosafo

Remove " or ' around them. Instead of foo: "001" write foo: 001.

vasily-kirichenko avatar Jun 02 '17 11:06 vasily-kirichenko

Removing the " or ' around 001 makes it a float

  branchCode: 1 //int
  branchCode: 01 //float
  branchCode: 001 //float
  branchCode: '1'  //timespan
  branchCode: '01' //timespan
  branchCode: '001' //timespan

rkosafo avatar Jun 02 '17 15:06 rkosafo

I have a similar problem.
CustomerId: 66123

I want load it as string. It is always recognized as TimeSpan.
I tried to use:

  • CustomerId: 66123 -> ok, this should be recognized as number
  • CustomerId: "66123"
  • CustomerId: '66123'
  • CustomerId: !!str 66123
  • CustomerId: | 66123
  • CustomerId: > 66123

alex-piccione avatar Feb 27 '19 21:02 alex-piccione

I was able to read "001" and "66123" as a strings using the constructor with inferTypesFromString set to false:

ValueA: "001"
ValueB: !!str 001
type Configuration = YamlConfig<"configuration.yaml">
// value is loaded as TimeSpan 

type Configuration2 = YamlConfig<"configuration.yaml", true, "", false>
// value is loaded as string

The intellisense sometime shows the previous "logic" (TimeSpan) but at runtime it works. Rename the "Configuration" type temporary make it reload the new type and showing the correct type.

alex-piccione avatar Mar 05 '19 22:03 alex-piccione