Skip to content

Instantly share code, notes, and snippets.

[PATCH] Added suggested change to YamlMappingNode legacy comatibilty code
From 0c7ca2a20911a332709c57871ee0e8ccf8563388 Mon Sep 17 00:00:00 2001
From: Fredrik Ludvigsen <fredrik@rain-games.com>
Date: Wed, 8 Feb 2017 14:48:02 +0100
Subject: [PATCH] Added suggested change to YamlMappingNode legacy comatibilty
code
---
.../RepresentationModel/YamlMappingNode.cs | 37 ++++++++++++----------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/Assets/Plugins/YamlDotNet/RepresentationModel/YamlMappingNode.cs b/Assets/Plugins/YamlDotNet/RepresentationModel/YamlMappingNode.cs
index 472e3f8..7fd4cdb 100644
--- a/Assets/Plugins/YamlDotNet/RepresentationModel/YamlMappingNode.cs
+++ b/Assets/Plugins/YamlDotNet/RepresentationModel/YamlMappingNode.cs
@@ -106,17 +106,18 @@ namespace YamlDotNet.RepresentationModel
/// <summary>
/// Initializes a new instance of the <see cref="YamlMappingNode"/> class.
/// </summary>
- public YamlMappingNode(params KeyValuePair<YamlNode, YamlNode>[] children)
- : this((IEnumerable<KeyValuePair<YamlNode, YamlNode>>)children)
+ public YamlMappingNode(KeyValuePair<YamlNode, YamlNode> firstChild, params KeyValuePair<YamlNode, YamlNode>[] otherChildren)
+ : this(firstChild, (IEnumerable<KeyValuePair<YamlNode, YamlNode>>)otherChildren)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="YamlMappingNode"/> class.
/// </summary>
- public YamlMappingNode(IEnumerable<KeyValuePair<YamlNode, YamlNode>> children)
+ public YamlMappingNode(KeyValuePair<YamlNode, YamlNode> firstChild, IEnumerable<KeyValuePair<YamlNode, YamlNode>> otherChildren)
{
- foreach (var child in children)
+ this.children.Add(firstChild);
+ foreach (var child in otherChildren)
{
this.children.Add(child);
}
@@ -125,29 +126,33 @@ namespace YamlDotNet.RepresentationModel
/// <summary>
/// Initializes a new instance of the <see cref="YamlMappingNode"/> class.
/// </summary>
- /// <param name="children">A sequence of <see cref="YamlNode"/> where even elements are keys and odd elements are values.</param>
- public YamlMappingNode(params YamlNode[] children)
- : this((IEnumerable<YamlNode>)children)
+ /// <param name="otherChildren">A sequence of <see cref="YamlNode"/> where even elements are keys and odd elements are values.</param>
+ public YamlMappingNode(YamlNode firstChild, params YamlNode[] otherChildren)
+ : this(firstChild, (IEnumerable<YamlNode>)otherChildren)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="YamlMappingNode"/> class.
/// </summary>
- /// <param name="children">A sequence of <see cref="YamlNode"/> where even elements are keys and odd elements are values.</param>
- public YamlMappingNode(IEnumerable<YamlNode> children)
+ /// <param name="otherChildren">A sequence of <see cref="YamlNode"/> where even elements are keys and odd elements are values.</param>
+ public YamlMappingNode(YamlNode firstChild, IEnumerable<YamlNode> otherChildren)
{
- using (var enumerator = children.GetEnumerator())
+ using (var enumerator = otherChildren.GetEnumerator())
{
- while (enumerator.MoveNext())
+ if (enumerator.MoveNext())
{
- var key = enumerator.Current;
- if (!enumerator.MoveNext())
+ Add(firstChild, enumerator.Current);
+ while (enumerator.MoveNext())
{
- throw new ArgumentException("When constructing a mapping node with a sequence, the number of elements of the sequence must be even.");
- }
+ var key = enumerator.Current;
+ if (!enumerator.MoveNext())
+ {
+ throw new ArgumentException("When constructing a mapping node with a sequence, the number of elements of the sequence must be even.");
+ }
- Add(key, enumerator.Current);
+ Add(key, enumerator.Current);
+ }
}
}
}
--
2.7.1.windows.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment