1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.IO;
using YamlDotNet.Serialization;

namespace Test
{
public class Test
{
static void Main()
{
// 读取
string str = File.ReadAllText("cat.yaml");
Animal cat = new DeserializerBuilder().Build().Deserialize<Animal>(str);
Console.WriteLine(cat.name);

// 写入
string str2 = new SerializerBuilder().Build().Serialize(cat);
Console.WriteLine(str2);
}
}

public class Animal
{
public string name { get; set; }
public int age { get; set; }
}
}