/// <summary> /// Performs a depth-first walk down the expand tree, copying and adding to the current path as it goes. When the bottom of a path is reached, the path is added to the overall set of paths. /// </summary> /// <param name="currentPath">The current path so far for this depth-first traversal of the tree. Starts out null.</param> /// <param name="currentNode">The current node of the expand tree.</param> /// <param name="rootNode">The root node of the expand tree.</param> private void ExtractExpandPathSegmentCollections(ExpandSegmentCollection currentPath, ExpandedProjectionNode currentNode, RootProjectionNode rootNode) { ExpandSegmentCollection nextPath = null; foreach (ExpandedNavigationSelectItem expandItem in currentNode.SelectExpandClause.SelectedItems.OfType<ExpandedNavigationSelectItem>()) { rootNode.ExpansionsSpecified = true; if (currentPath == null) { nextPath = new ExpandSegmentCollection(); } else { // create a copy of the current path. nextPath = new ExpandSegmentCollection(currentPath.Count); nextPath.AddRange(currentPath); } var segment = this.CreateExpandSegment(expandItem, currentNode.ResourceType); nextPath.Add(segment); ExpandedProjectionNode childNode = currentNode.AddExpandedNode(segment, expandItem.SelectAndExpand); // if there are any derived expansions in the tree, set the rootNode.DerivedExpansionsSpecified to true. if (currentNode.HasExpandedPropertyOnDerivedType) { rootNode.ExpansionOnDerivedTypesSpecified = true; } this.ExtractExpandPathSegmentCollections(nextPath, childNode, rootNode); } if (nextPath == null && currentPath != null) { this.expandPaths.Add(currentPath); } }