/** * Iterate over all the Define nodes in this node and add them as macros */ public void AddMacros(XmlNode node) { if (_nodes == null) { _nodes = new Dictionary<XmlNode, bool>(); } try { _nodes.Add(node, true); } catch (System.ArgumentException) { throw new JRunXmlException(node, "Attempted to add a node's macros twice"); } foreach (var defNode in node.SelectXmlNodes("Define")) { var name = defNode.GetAttributeValue("name"); if (name != null && name.Length > 0) { var value = defNode.GetAttributeValue("value"); if (value != null) { if (_macros == null) { _macros = new Dictionary<string, XmlMacroValue>(StringComparer.OrdinalIgnoreCase); } // overwrite any macros that are already there _macros.Remove(name); _macros.Add(name, new XmlMacroValue(value)); } else { throw new JRunXmlException(defNode, "Define nodes must have a value"); } } else { throw new JRunXmlException(defNode, "Define nodes must have a name"); } } }