Responsible: MSE
Simple encapsulation of YamlDotNet and the querying extension YamlPathForYamlDotNet to read and navigate yaml documents
The IYAML interface provides method to read values from a yaml or naviagte to deeper nodes:
/// <summary>
/// methods for reading a yaml file
/// </summary>
public interface IYaml
{
/// <summary>
/// lists all nodes at the given path
/// </summary>
IList<IYaml> Nodes(string path);
/// <summary>
/// the value at the given path
/// </summary>
string Value(string path, string def = "");
/// <summary>
/// the values at the given path
/// </summary>
IList<string> Values(string path);
YamlNode AsNode();
}
To use it just call the implementation class new YamlOf(yourYamlContentText)
and navigate with yaml path, which is documented here
yamlContent:
root:
object:
name: test
type: text
value: hello
objectlist:
- name: test1
type: text
value: hello
- name: test2
type: number
value: 2
list:
- test1
- test2
- test3
[Fact]
public void ReadsValues()
{
var yaml = new YamlOf(yamlContent);
Assert.Equal(
new ManyOf("test1", "test2", "test3"),
yaml.Values("/root/list/*")
);
}