public void AssignAnchors(YamlDocument document) { existingAnchors.Clear(); visitedNodes.Clear(); document.Accept(this); Random random = new Random(); foreach (KeyValuePair <YamlNode, bool> visitedNode in visitedNodes) { if (visitedNode.Value) { string text; if (string.IsNullOrEmpty(visitedNode.Key.Anchor) || existingAnchors.Contains(visitedNode.Key.Anchor)) { do { text = random.Next().ToString(CultureInfo.InvariantCulture); }while (existingAnchors.Contains(text)); } else { text = visitedNode.Key.Anchor; } existingAnchors.Add(text); visitedNode.Key.Anchor = text; } } }
public void AssignAnchors(YamlDocument document) { existingAnchors.Clear(); visitedNodes.Clear(); document.Accept(this); var random = new Random(); foreach (var visitedNode in visitedNodes) { if (visitedNode.Value) { string anchor; // If the existing anchor is not already used, we can have it if (!string.IsNullOrEmpty(visitedNode.Key.Anchor) && !existingAnchors.Contains(visitedNode.Key.Anchor)) { anchor = visitedNode.Key.Anchor; } else { do { anchor = random.Next().ToString(CultureInfo.InvariantCulture); } while (existingAnchors.Contains(anchor)); } existingAnchors.Add(anchor); visitedNode.Key.Anchor = anchor; } } }
public void AssignAnchors(YamlDocument document) { existingAnchors.Clear(); visitedNodes.Clear(); document.Accept(this); Random random = new Random(); foreach (var visitedNode in visitedNodes) { if (visitedNode.Value) { string anchor; do { anchor = random.Next().ToString(CultureInfo.InvariantCulture); } while (existingAnchors.Contains(anchor)); existingAnchors.Add(anchor); visitedNode.Key.Anchor = anchor; } } }
public void AssignAnchors(YamlDocument document) { this.existingAnchors.Clear(); this.visitedNodes.Clear(); document.Accept(this); Random random = new Random(); foreach (KeyValuePair <YamlNode, bool> pair in this.visitedNodes) { if (pair.Value) { while (true) { string item = random.Next().ToString(CultureInfo.InvariantCulture); if (!this.existingAnchors.Contains(item)) { this.existingAnchors.Add(item); pair.Key.Anchor = item; break; } } } } }
/// <summary> /// Converts a <see cref="YamlDocument"/> to <see cref="XmlDocument"/>. /// </summary> /// <param name="document">The YAML document to convert.</param> /// <returns></returns> public XmlDocument ToXml(YamlDocument document) { YamlToXmlDocumentVisitor visitor = new YamlToXmlDocumentVisitor(options); document.Accept(visitor); return visitor.Document; }