Exemple #1
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);
        }
Exemple #2
0
 /// <summary>
 /// Handle an ExpandedReferenceSelectItem
 /// </summary>
 /// <param name="item">the item to Handle</param>
 public virtual void Handle(ExpandedReferenceSelectItem item)
 {
     throw new NotImplementedException();
 }
Exemple #3
0
 /// <summary>
 /// Translate an ExpandedReferenceSelectItem
 /// </summary>
 /// <param name="item">the item to Translate</param>
 /// <returns>Defined by the implementer</returns>
 public virtual T Translate(ExpandedReferenceSelectItem item)
 {
     throw new NotImplementedException();
 }