Код: Выделить всё
public struct Choice
{
public string result;
public string nextBranch;
}
public struct Branch
{
public Dictionary choices;
}
public class ChoiceTree
{
public Dictionary branches;
// some other properties
// some methods
}
Код: Выделить всё
branches:
- Key: "main1"
Value:
choices:
- Key: "few minutes"
Value:
result: "S"
nextBranch: "refuse"
- Key: "hold on"
Value:
result: "D"
nextBranch: "refuse"
- Key: "of course"
Value:
result: "LS"
nextBranch: "accept"
- Key: "fine"
Value:
result: "HD"
nextBranch: "accept"
- Key: "refuse"
Value:
choices:
- Key: "reluctant"
Value:
result: "HH"
nextBranch: "accept"
- Key: "happily"
Value:
result: "L"
nextBranch: "accept"
# more branches below...
Код: Выделить всё
public class YamlChoiceTreeeParser
{
public YamlChoiceTreeeParser(string filePath)
{
if (!File.Exists(filePath))
{
throw new Exception("YAML file not found");
}
using (StreamReader sr = new StreamReader(filePath))
{
var deserializer = new DeserializerBuilder()
.Build();
var choiceTree = deserializer.Deserialize(sr);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... -yaml-file
Мобильная версия