/// <summary> /// Expands a node into child nodes. /// </summary> /// <param name="node">The node to expand</param> /// <param name="model">The ODCM model</param> /// <returns>The child nodes if the node can be expanded, otherwise an empty list.</returns> private static IEnumerable <OdcmNode> CreateChildNodes(this OdcmNode node, OdcmModel model) { if (node == null) { throw new ArgumentNullException(nameof(node)); } if (model == null) { throw new ArgumentNullException(nameof(model)); } // Identify the kind of ODCM element this node represents and expand it if we need to OdcmProperty obj = node.OdcmProperty; IEnumerable <OdcmProperty> childObjects = obj.Type.GetChildObjects(model); // Don't allow loops in the list of ODCM nodes ICollection <string> parents = new HashSet <string>(); OdcmNode currentNode = node; while (currentNode != null) { parents.Add(currentNode.OdcmProperty.CanonicalName()); currentNode = currentNode.Parent; } return(childObjects // Filter out the children we've already seen so we can avoid loops .Where(child => !parents.Contains(child.CanonicalName())) // Add the child nodes to the current node .Select(child => node.CreateChildNode(child))); }