/// <summary>
 /// Build the top level select clause as a string.
 /// </summary>
 /// <param name="selectExpandClause">top level select expand clause.</param>
 /// <returns>the string representation of the top level select clause.</returns>
 private static string BuildTopLevelSelect(SelectExpandClause selectExpandClause)
 {
     // Special case to build the top level select clause (this it the only time that we actualy
     // modify the selectClause because in V4 the the top level select clause can only modify the top
     // level).
     return(String.Join(",", selectExpandClause.GetCurrentLevelSelectList().ToArray()));
 }
        /// <summary>
        /// Traverse a SelectExpandClause using given functions.
        /// </summary>
        /// <typeparam name="T">Type of the sub processing result for expand items.</typeparam>
        /// <param name="selectExpandClause">The select expand clause for evaluation.</param>
        /// <param name="processSubResult">The method to deal with sub expand result.</param>
        /// <param name="combineSelectAndExpand">The method to combine select and expand result lists.</param>
        /// <param name="result">The result of the traversing.</param>
        internal static void Traverse <T>(this SelectExpandClause selectExpandClause, Func <string, T, T> processSubResult, Func <IList <string>, IList <T>, T> combineSelectAndExpand, out T result)
        {
            List <string> selectList = selectExpandClause.GetCurrentLevelSelectList();
            List <T>      expandList = new List <T>();

            foreach (ExpandedNavigationSelectItem expandSelectItem in selectExpandClause.SelectedItems.Where(I => I.GetType() == typeof(ExpandedNavigationSelectItem)))
            {
                string currentExpandClause = String.Join("/", expandSelectItem.PathToNavigationProperty.WalkWith(PathSegmentToStringTranslator.Instance).ToArray());
                T      subResult           = default(T);
                if (expandSelectItem.SelectAndExpand.SelectedItems.Any())
                {
                    Traverse(expandSelectItem.SelectAndExpand, processSubResult, combineSelectAndExpand, out subResult);
                }

                var expandItem = processSubResult(currentExpandClause, subResult);
                if (expandItem != null)
                {
                    expandList.Add(expandItem);
                }
            }

            foreach (ExpandedReferenceSelectItem expandSelectItem in selectExpandClause.SelectedItems.Where(I => I.GetType() == typeof(ExpandedReferenceSelectItem)))
            {
                string currentExpandClause = String.Join("/", expandSelectItem.PathToNavigationProperty.WalkWith(PathSegmentToStringTranslator.Instance).ToArray());
                currentExpandClause += "/$ref";

                var expandItem = processSubResult(currentExpandClause, default(T));
                if (expandItem != null)
                {
                    expandList.Add(expandItem);
                }
            }

            result = combineSelectAndExpand(selectList, expandList);
        }
Beispiel #3
0
        /// <summary>
        /// Traverse a SelectExpandClause using given functions.
        /// </summary>
        /// <typeparam name="T">Type of the sub processing result for expand items.</typeparam>
        /// <param name="selectExpandClause">The select expand clause for evaluation.</param>
        /// <param name="processSubResult">The method to deal with sub expand result.</param>
        /// <param name="combineSelectAndExpand">The method to combine select and expand result lists.</param>
        /// <param name="processApply">The method to deal with apply result.</param>
        /// <param name="result">The result of the traversing.</param>
        internal static void Traverse <T>(this SelectExpandClause selectExpandClause, Func <string, T, T> processSubResult, Func <IList <string>, IList <T>, T> combineSelectAndExpand, Func <ApplyClause, T> processApply, out T result)
        {
            List <string> selectList = selectExpandClause.GetCurrentLevelSelectList();
            List <T>      expandList = new List <T>();

            foreach (SelectItem selectItem in selectExpandClause.SelectedItems)
            {
                // $expand=..../$ref
                ExpandedNavigationSelectItem expandSelectItem = selectItem as ExpandedNavigationSelectItem;

                if (expandSelectItem != null)
                {
                    string currentExpandClause = String.Join("/", expandSelectItem.PathToNavigationProperty.WalkWith(PathSegmentToStringTranslator.Instance).ToArray());
                    T      subResult           = default(T);
                    if (expandSelectItem.SelectAndExpand.SelectedItems.Any())
                    {
                        Traverse(expandSelectItem.SelectAndExpand, processSubResult, combineSelectAndExpand, processApply, out subResult);
                    }

                    if (expandSelectItem.ApplyOption != null && processApply != null)
                    {
                        subResult = processApply(expandSelectItem.ApplyOption);
                    }

                    var expandItem = processSubResult(currentExpandClause, subResult);
                    if (expandItem != null)
                    {
                        expandList.Add(expandItem);
                    }
                }
                else
                {
                    ExpandedReferenceSelectItem expandRefItem = selectItem as ExpandedReferenceSelectItem;

                    if (expandRefItem != null)
                    {
                        string currentExpandClause = String.Join("/", expandRefItem.PathToNavigationProperty.WalkWith(PathSegmentToStringTranslator.Instance).ToArray());
                        currentExpandClause += "/$ref";

                        var expandItem = processSubResult(currentExpandClause, default(T));
                        if (expandItem != null)
                        {
                            expandList.Add(expandItem);
                        }
                    }
                }
            }

            result = combineSelectAndExpand(selectList, expandList);
        }