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

Is there a way to prevent certain conversions? #123

Open rkosafo opened 7 years ago

rkosafo commented 7 years ago

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.

vasily-kirichenko commented 7 years ago

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

rkosafo commented 7 years ago

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
alex-piccione commented 5 years ago

I have a similar problem.
CustomerId: 66123

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

alex-piccione commented 5 years ago

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.