0

I have a yaml where both of the following formats are acceptable -

  args:
    buildno: 1
    gitcommithash: cdc3b19

And

  args:
    - buildno=1
    - gitcommithash=cdc3b19

With current YamlDotnet configuration,

[YamlMember(Alias = "args")]
public Dictionary<string, string> Args { get; set; }

I can parse when the yaml is of format no. 1. How can I modify my YamlDotNet code to accept both formats? i.e. Accepting list as well as Dictionary for Args?

Pratik
  • 695
  • 2
  • 11
  • 29

1 Answers1

0

The easiest way to do that is to create a class that implements both IDictionary<string, string> and IList<string>. You could try inheriting from Dictionary<string, string> and implement the list interface. I think it would be enough to implement the Add method from IList, where you split the string by the = character and add to the dictionary.

There are other ways but this is the simplest.

Antoine Aubry
  • 12,203
  • 10
  • 45
  • 74