/// <summary> /// Normalize a SelectToken into something that can be used to trim an expand tree. /// </summary> /// <param name="treeToNormalize">The select token to normalize</param> /// <returns>Normalized SelectToken</returns> public static SelectToken NormalizeSelectTree(SelectToken treeToNormalize) { PathReverser pathReverser = new PathReverser(); List <PathSegmentToken> invertedPaths = (from property in treeToNormalize.Properties select property.Accept(pathReverser)).ToList(); // to normalize a select token we just need to invert its paths, so that // we match the ordering on an ExpandToken. return(new SelectToken(invertedPaths)); }
/// <summary> /// Invert the all of the paths in an expandToken, such that they are now in the same order as they are present in the /// base url /// </summary> /// <param name="treeToInvert">the tree to invert paths on</param> /// <returns>a new tree with all of its paths inverted</returns> public static ExpandToken InvertPaths(ExpandToken treeToInvert) { // iterate through each expand term token, and reverse the tree in its path property List <ExpandTermToken> updatedTerms = new List <ExpandTermToken>(); foreach (ExpandTermToken term in treeToInvert.ExpandTerms) { PathReverser pathReverser = new PathReverser(); PathSegmentToken reversedPath = term.PathToNavProp.Accept(pathReverser); ExpandTermToken newTerm = new ExpandTermToken(reversedPath, term.FilterOption, term.OrderByOption, term.TopOption, term.SkipOption, term.InlineCountOption, term.SelectOption, term.ExpandOption); updatedTerms.Add(newTerm); } return(new ExpandToken(updatedTerms)); }