Esempio n. 1
0
        /// <summary>
        /// Add a select item to the current list of selection items
        /// </summary>
        /// <param name="itemToAdd">The item to add</param>
        internal void AddToSelectedItems(SelectItem itemToAdd)
        {
            ExceptionUtils.CheckArgumentNotNull(itemToAdd, "itemToAdd");

            if (this.selectedItems.Any(x => x is WildcardSelectItem) && UriUtils.IsStructuralOrNavigationPropertySelectionItem(itemToAdd))
            {
                return;
            }

            bool isWildcard = itemToAdd is WildcardSelectItem;

            List <SelectItem> newSelectedItems = new List <SelectItem>();

            foreach (SelectItem selectedItem in this.selectedItems)
            {
                if (isWildcard)
                {
                    if (!UriUtils.IsStructuralSelectionItem(selectedItem))
                    {
                        newSelectedItems.Add(selectedItem);
                    }
                }
                else
                {
                    newSelectedItems.Add(selectedItem);
                }
            }

            newSelectedItems.Add(itemToAdd);
            this.selectedItems = new ReadOnlyCollection <SelectItem>(newSelectedItems);
        }
Esempio n. 2
0
        /// <summary>
        /// Add a selection item to the current selection.
        /// </summary>
        /// <param name="itemToAdd">the new selection item to add</param>
        internal void AddSelectItem(SelectItem itemToAdd)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(this.usedInternalLegacyConsturctor, "Should never call this property unless we used internal ctor.");
            ExceptionUtils.CheckArgumentNotNull(itemToAdd, "itemToAdd");

            // if this is already an all selection, then adding a specific selection item is purely redundant.
            if (this.selection is AllSelection)
            {
                return;
            }

            // otherwise, if it is either an expands-only or unkown selection, convert it to a partial selection before adding this item.
            if (this.selection is ExpansionsOnly || this.selection is UnknownSelection)
            {
                this.selection = new PartialSelection(new List <SelectItem>()
                {
                    itemToAdd
                });
            }
            else
            {
                // TODO: why do we create a whole new list?
                List <SelectItem> newSelections = ((PartialSelection)this.selection).SelectedItems.ToList();
                if (itemToAdd is WildcardSelectItem)
                {
                    IEnumerable <SelectItem> structualAndNavItems = newSelections.Where(UriUtils.IsStructuralOrNavigationPropertySelectionItem).ToArray();
                    foreach (SelectItem item in structualAndNavItems)
                    {
                        newSelections.Remove(item);
                    }
                }
                else if (UriUtils.IsStructuralOrNavigationPropertySelectionItem(itemToAdd))
                {
                    if (newSelections.Any(item => item is WildcardSelectItem))
                    {
                        return;
                    }
                }

                newSelections.Add(itemToAdd);
                this.selection = new PartialSelection(newSelections);
            }
        }