-
Notifications
You must be signed in to change notification settings - Fork 0
/
YamlImporter.cs
33 lines (28 loc) · 885 Bytes
/
YamlImporter.cs
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
28
29
30
31
32
33
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YamlDotNet.Core;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization;
namespace StarArmory
{
public class YamlImporter
{
public static T getObjectFrom<T>(string filePath)
{
string content = File.ReadAllText(filePath);
return getObjectFromYaml<T>(content);
}
public static T getObjectFromYaml<T>(string yaml)
{
var deserializer = new DeserializerBuilder()
.WithNamingConvention(PascalCaseNamingConvention.Instance) // see height_in_inches in sample yml
.Build();
//yml contains a string containing your YAML
T obj = deserializer.Deserialize<T>(yaml);
return obj;
}
}
}