/// <summary>
        /// Adds the specified node to the anchor list.
        /// </summary>
        /// <param name="node">The node.</param>
        public void AddAnchor(YamlNode node)
        {
            if (node.Anchor == null)
            {
                throw new ArgumentException("The specified node does not have an anchor");
            }

            if (anchors.ContainsKey(node.Anchor))
            {
                throw new DuplicateAnchorException(node.Start, node.End, string.Format(CultureInfo.InvariantCulture, "The anchor '{0}' already exists", node.Anchor));
            }

            anchors.Add(node.Anchor, node);
        }
示例#2
0
 private object GetValue(YamlNode key)
 {
     YamlNode result;
     if (node.Children.TryGetValue(key, out result))
     {
         return ConvertToDynamic(result);
     }
     return null;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="YamlDocument"/> class.
 /// </summary>
 public YamlDocument(YamlNode rootNode)
 {
     RootNode = rootNode;
 }
 private void VisitNode(YamlNode node)
 {
     if (string.IsNullOrEmpty(node.Anchor))
     {
         bool isDuplicate;
         if (visitedNodes.TryGetValue(node, out isDuplicate))
         {
             if (!isDuplicate)
             {
                 visitedNodes[node] = true;
             }
         }
         else
         {
             visitedNodes.Add(node, false);
         }
     }
     else
     {
         existingAnchors.Add(node.Anchor);
     }
 }
示例#5
0
		/// <summary>
		/// Initializes a new instance of the <see cref="YamlDocument"/> class.
		/// </summary>
		/// <param name="events">The events.</param>
		internal YamlDocument(EventReader events)
		{
			DocumentLoadingState state = new DocumentLoadingState();

			events.Expect<DocumentStart>();

			while (!events.Accept<DocumentEnd>())
			{
				Debug.Assert(RootNode == null);
				RootNode = YamlNode.ParseNode(events, state);

				if (RootNode is YamlAliasNode)
				{
					throw new YamlException();
				}
			}

			state.ResolveAliases();

#if DEBUG
			foreach (var node in AllNodes)
			{
				if (node is YamlAliasNode)
				{
					throw new InvalidOperationException("Error in alias resolution.");
				}
			}
#endif

			events.Expect<DocumentEnd>();
		}
示例#6
0
		/// <summary>
		/// Initializes a new instance of the <see cref="YamlDocument"/> class with a single scalar node.
		/// </summary>
		public YamlDocument(string rootNode)
		{
			RootNode = new YamlScalarNode(rootNode);
		}
示例#7
0
 /// <summary>
 /// Provides a basic implementation of Object.Equals 
 /// </summary>
 protected bool Equals(YamlNode other)
 {
     // Do not use the anchor in the equality comparison because that would prevent anchored nodes from being found in dictionaries.
     return SafeEquals(Tag, other.Tag);
 }
 /// <summary>
 /// Adds the specified node to the collection of nodes with unresolved aliases.
 /// </summary>
 /// <param name="node">
 /// The <see cref="YamlNode"/> that has unresolved aliases.
 /// </param>
 public void AddNodeWithUnresolvedAliases(YamlNode node)
 {
     nodesWithUnresolvedAliases.Add(node);
 }