IEnumerable <SchemaPath> ExpandProperty(SchemaVertex from, QueueItem tree, IEnumerable <SchemaEdge> currentPath) { // get the edge in the graph where it is connected from the same type as the from vertex, and the property name matches. var edge = graph.Edges.FirstOrDefault(e => e.From.Value.TypeId == from.Value.TypeId && e.Value.Name == tree.Root.Value.Text); if (edge == null) { yield break; } if (tree.IsDirectPropertyAccess()) { var childEdgePath = new List <SchemaEdge>(currentPath); childEdgePath.Add(edge); yield return(new SchemaPath(childEdgePath)); } var cPath = new List <SchemaEdge>(currentPath); cPath.Add(edge); yield return(new SchemaPath(cPath)); foreach (var child in tree.Children) { foreach (var path in Traverse(edge.To, child.Item2, cPath).Distinct()) { yield return(path); } } }
IEnumerable <SchemaPath> TraverseChildren(SchemaVertex from, QueueItem tree, IEnumerable <SchemaEdge> currentPath) { foreach (var path in tree.Children.SelectMany(x => Traverse(from, x.Item2, currentPath))) { yield return(path); } }
public IEnumerable <SchemaPath> Traverse(SchemaVertex from, QueueItem tree, IEnumerable <SchemaEdge> currentPath = null) { if (currentPath == null) { currentPath = new List <SchemaEdge>(); } if (tree.Representation == TextRepresentation.ExpandProperty) { return(ExpandProperty(from, tree, currentPath)); } bool IsPassThrough(string rep) { return(rep == TextRepresentation.ListOfExpands || rep == TextRepresentation.ListOfClause || rep == TextRepresentation.ExpandExpression); } if (IsPassThrough(tree.Representation)) { return(TraverseChildren(from, tree, currentPath).Distinct()); } if (tree.Representation == TextRepresentation.SelectExpression) { SelectAddFunc(AppendPathToQueueItem(currentPath, tree.Children.First().Item2)); return(new List <SchemaPath>()); } if (tree.Representation == TextRepresentation.FilterExpression) { FilterAddFunc(AppendPathToQueueItem(currentPath, tree.Children.First().Item2)); return(new List <SchemaPath>()); } throw new NotImplementedException("Unknown tree type: " + tree.Representation); }