Can someone help me with this. How to use YamlDotNet to deserialize an object?
My code:
open YamlDotNet
open YamlDotNet.Serialization
open System
open System.IO
let ss1 (obj, f) =
use tw = File.CreateText(f)
let s = new Serializer()
s.Serialize(tw, obj)
type tobject() =
member this.a = "a"
member this.b = "b"
let f = "xxx.yml"
let obj = new tobject()
ss1(obj, f)
let de = new Deserializer()
let file = new FileStream(f, FileMode.Open, FileAccess.Read)
let stream = new StreamReader(file)
// let conf = de.Deserialize(stream)
let conf = de.Deserialize<tobject>(stream) // YamlException occur here!
If I write:
let conf = de.Deserialize(stream)
I have:
val conf : obj = dict [("a","a");("b","b")]
I wish I can have working F# code of this C# example https://dotnetfiddle.net/HD2JXM
I rewrote the code by reference (https://dotnetfiddle.net/HD2JXM)in F#:
Print:
The writing style is not F#, but it's easy to fix