Throw a slightly more useful error on duplicate keys

This commit is contained in:
Paul Chote
2011-05-16 19:27:56 +12:00
parent d7f009b218
commit 239a96718d

View File

@@ -66,7 +66,20 @@ namespace OpenRA.FileFormats
public string Value;
public List<MiniYamlNode> Nodes;
public Dictionary<string, MiniYaml> NodesDict { get { return Nodes.ToDictionary( x => x.Key, x => x.Value ); } }
public Dictionary<string, MiniYaml> NodesDict
{
get
{
var ret = new Dictionary<string, MiniYaml>();
foreach (var y in Nodes)
{
if (ret.ContainsKey(y.Key))
throw new InvalidDataException("Duplicate key `{0}' in MiniYaml".F(y.Key));
ret.Add(y.Key, y.Value);
}
return ret;
}
}
public MiniYaml( string value ) : this( value, null ) { }