From 239a96718dc172ecf8f06786f89ca5e85b512e44 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 16 May 2011 19:27:56 +1200 Subject: [PATCH] Throw a slightly more useful error on duplicate keys --- OpenRA.FileFormats/MiniYaml.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/OpenRA.FileFormats/MiniYaml.cs b/OpenRA.FileFormats/MiniYaml.cs index cb3d6b948e..c13f38dde8 100755 --- a/OpenRA.FileFormats/MiniYaml.cs +++ b/OpenRA.FileFormats/MiniYaml.cs @@ -66,7 +66,20 @@ namespace OpenRA.FileFormats public string Value; public List Nodes; - public Dictionary NodesDict { get { return Nodes.ToDictionary( x => x.Key, x => x.Value ); } } + public Dictionary NodesDict + { + get + { + var ret = new Dictionary(); + 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 ) { }