aaubry / YamlDotNet

YamlDotNet is a .NET library for YAML
MIT License
2.48k stars 466 forks source link

Support for FSharp BCL List deserialization #932

Open MrLuje opened 2 weeks ago

MrLuje commented 2 weeks ago

While looking at #913, I noticed that there is currently no support for F# List.

In F# BCL, there is basically 3 main collections :

#r "nuget: YamlDotNet"

open YamlDotNet

[<CLIMutable>]
type MyType = { 
    Numbers: int list 
}

open YamlDotNet.Serialization

let d = Deserializer()
"""
Numbers: [1, 2, 3]
"""
|> d.Deserialize<MyType>
|> printfn "%A"

gives the following error :

(Line: 2, Col: 10, Idx: 10) - (Line: 2, Col: 10, Idx: 10): No node deserializer was able to deserialize the node into type Microsoft.FSharp.Collections.FSharpList`1[[System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], FSharp.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Stopped due to error

If that's ok, I can add support for it, following the same approach as #930 (probably by adding a new deserializer in DeserializerBuilder)