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

Yaml type provider: Can't read a list of objects #167

Open Kurren123 opened 2 years ago

Kurren123 commented 2 years ago

My config.yaml:

Targets:
  - Target: 1 0 1 0
    NoSlots: 2

  - Target: -1 0 -1 -1
    NoSlots: 2

Tiles:
  - 1 0 0 0
  - 0 0 1 0
  - -1 0 0 0
  - 0 0 -1 -1

My code:

open FSharp.Configuration
type Config = YamlConfig<"config.yaml">
let config = Config()
printfn "Number of targets: %d" config.Targets.Count

Output: Number of targets: 1

Operating system: Windows Target framework: .net 6 Package version: 2.0.0

Any help to be able to parse the list of objects "Targets" would be much appreciated!

MrLuje commented 1 year ago

As a workaround, it works if you explicitly load the configuration file at runtime :

  open FSharp.Configuration
  type Config = YamlConfig<"config.yaml">
  let config = Config()
+ config.Load "config.yaml"
  printfn "Number of targets: %d" config.Targets.Count
64J0 commented 12 months ago

I think we can add a new test to check this scenario automatically.

If no one works on it before, I'm going to take a look later.