2016-07-28 78 views
5

我已經使用地圖的YAML集合在我的配置文件的嘗試:F#YAML類提供商

Companies: 
    - code: 11 
    name: A 
    country: FR 
    functionalCurrency: EUR 
    - code: 12 
    name: B 
    country: GB 
    functionalCurrency: GBP 

但是,試圖與類型提供商讀它的時候,它只能找到列表的第一個結果。

有了:

open FSharp.Configuration 
    type CompaniesConfig = YamlConfig<"Config.yaml"> 
    let config = CompaniesConfig() 

輸出爲:

val config : CompaniesConfig = 
    Companies: 
    - code: 11 
     name: A 
     country: FR 
     functionalCurrency: EUR 

試圖解析在線工作的代碼,所以我不知道這是否是一個庫限制或...?

感謝您的幫助

回答

3

實際上你需要加載的文件,不僅如果你想用它來直接獲得工作模式:config.Load(yamlFile)。這應該在文檔中更明確。我在鏈接中使用了示例文件。

#if INTERACTIVE 
#r @"..\packages\FSharp.Configuration.0.6.1\lib\net40\FSharp.Configuration.dll" 
#endif 

open FSharp.Configuration 
open System.IO 

/// https://github.com/fsprojects/FSharp.Configuration/blob/master/tests/FSharp.Configuration.Tests/Lists.yaml 

[<Literal>] 
let yamlFile = __SOURCE_DIRECTORY__ + "..\Lists.yaml" 

File.Exists yamlFile 

type TestConfig = YamlConfig<yamlFile> 
let config = TestConfig() 

config.Load(yamlFile) 
config.items.Count 
config.items 

而且我得到這兩個項目:

> 
val it : int = 2 
> 
val it : System.Collections.Generic.IList<TestConfig.items_Item_Type> = 
    seq 
    [FSharp.Configuration.TestConfig+items_Item_Type 
     {descrip = "Water Bucket (Filled)"; 
     part_no = "A4786"; 
     price = 147; 
     quantity = 4;}; 
    FSharp.Configuration.TestConfig+items_Item_Type 
     {descrip = "High Heeled "Ruby" Slippers"; 
     part_no = "E1628"; 
     price = 10027; 
     quantity = 1;}] 
>