ARTICLE AD BOX
Here's the general structure:
public struct Choice { public string result; public string nextBranch; } public struct Branch { public Dictionary<string, Choice> choices; } public class ChoiceTree { public Dictionary<string, Branch> branches; // some other properties // some methods }And I'm currently manually filling up my ChoiceTree object with textboxes because this is a WPF project. I'd like, instead, to parse them from a YAML file. I've made this as a starting point. I have no idea if it's set up correctly, but I did at least use an online checker to make sure the syntax is correct:
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: - Key: "reluctant" Value: choices: result: "HH" nextBranch: "accept" - Key: "happily" Value: choices: result: "L" nextBranch: "accept"I think the closest I've gotten so far is following this example. And by "closest" I mean, at least the code below compiles. But it does not work, and I have no idea why.
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<ChoiceTree>(sr); } } }I've tried a bunch of different variations on the yaml file, and a bunch of different examples, but I can't even step into the last line without an exception.
