/// <summary> /// Build a wildcard selection item /// </summary> /// <param name="tokenIn">the token to bind to a wildcard</param> /// <param name="model">the model to search for this wildcard</param> /// <param name="item">the new wildcard selection item, if we found one</param> /// <returns>true if we successfully bound to a wildcard, false otherwise</returns> public static bool TryBindAsWildcard(PathSegmentToken tokenIn, IEdmModel model, out SelectItem item) { bool isTypeToken = tokenIn.IsNamespaceOrContainerQualified(); bool wildcard = tokenIn.Identifier.EndsWith("*", StringComparison.Ordinal); if (isTypeToken && wildcard) { string namespaceName = tokenIn.Identifier.Substring(0, tokenIn.Identifier.Length - 2); if (model.DeclaredNamespaces.Any(declaredNamespace => declaredNamespace.Equals(namespaceName, StringComparison.Ordinal))) { item = new NamespaceQualifiedWildcardSelectItem(namespaceName); return(true); } } if (tokenIn.Identifier == "*") { item = new WildcardSelectItem(); return(true); } item = null; return(false); }
/// <summary> /// Gets a list of strings representing current selected property name in current level. /// </summary> /// <param name="selectExpandClause">The select expand clause used.</param> /// <returns>String list generated from selected items</returns> internal static List <string> GetCurrentLevelSelectList(this SelectExpandClause selectExpandClause) { HashSet <string> levelSelectList = new HashSet <string>(); List <string> masterSelectList = new List <string>(); foreach (var selectItem in selectExpandClause.SelectedItems) { if (selectItem is WildcardSelectItem) { levelSelectList.Add("*"); continue; } NamespaceQualifiedWildcardSelectItem namespaceQualifiedWildcard = selectItem as NamespaceQualifiedWildcardSelectItem; if (namespaceQualifiedWildcard != null) { levelSelectList.Add(namespaceQualifiedWildcard.Namespace + ".*"); continue; } PathSelectItem pathSelectItem = selectItem as PathSelectItem; if (pathSelectItem != null) { IList <string> pathSelectItems = GetSelectStringFromPathSelectItem(pathSelectItem); for (int i = 0; i < pathSelectItems.Count; i++) { levelSelectList.Add(pathSelectItems[i]); } } } // If a select item is a child of a complex property, and that complex property already has all properties selected, // then the child is redundant and should not be included in the contextUrl. i.e.; $select=address,address/city => address foreach (string item in levelSelectList) { if (!levelSelectList.Contains(GetPreviousSegments(item))) { masterSelectList.Add(item); } } return(masterSelectList); }
/// <summary> /// Get the string representation of a select item (that isn't an expandedNavPropSelectItem /// </summary> /// <param name="selectedItem">the select item to translate</param> /// <returns>the string representation of this select item, or null if the select item is an expandedNavPropSelectItem</returns> private static string GetSelectString(SelectItem selectedItem) { WildcardSelectItem wildcardSelect = selectedItem as WildcardSelectItem; NamespaceQualifiedWildcardSelectItem namespaceQualifiedWildcard = selectedItem as NamespaceQualifiedWildcardSelectItem; PathSelectItem pathSelectItem = selectedItem as PathSelectItem; if (wildcardSelect != null) { return("*"); } else if (namespaceQualifiedWildcard != null) { return(namespaceQualifiedWildcard.Namespace + ".*"); } else if (pathSelectItem != null) { return(String.Join("/", pathSelectItem.SelectedPath.WalkWith(PathSegmentToStringTranslator.Instance).ToArray())); } else { return(null); } }
/// <summary> /// Handle a ContainerQualifiedWildcardSelectItem /// </summary> /// <param name="item">the item to Handle</param> public virtual void Handle(NamespaceQualifiedWildcardSelectItem item) { throw new NotImplementedException(); }
/// <summary> /// Translate a ContainerQualifiedWildcardSelectItem /// </summary> /// <param name="item">the item to Translate</param> /// <returns>Defined by the implementer</returns> public virtual T Translate(NamespaceQualifiedWildcardSelectItem item) { throw new NotImplementedException(); }