Skip to content

Encapsulation of YamlDotNet and Query Extensions to read and navigate yaml documents

Notifications You must be signed in to change notification settings

icarus-consulting/Yamly

Repository files navigation

EO principles respected here

Responsible: MSE

Yamly

Simple encapsulation of YamlDotNet and the querying extension YamlPathForYamlDotNet to read and navigate yaml documents

Usage

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

Examples

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/*")
    );
}

About

Encapsulation of YamlDotNet and Query Extensions to read and navigate yaml documents

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages