コード例 #1
0
        /// <summary>
        /// Adds a <see cref="ToolItem"/> to the collection.
        /// </summary>
        /// <param name="item">The <see cref="ToolItem"/> to add to the collection.</param>
        /// <returns>The position into which the new element was inserted.</returns>
        public int Add(ToolItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (_isTrackingViewState)
            {
                ((IStateManager)item).TrackViewState();
                item.SetDirty();
            }

            return(_items.Add(item));
        }
コード例 #2
0
        /// <summary>
        /// When implemented by a class, saves the changes to a server control's view state to an
        /// <see cref="T:System.Object"/> .
        /// </summary>
        /// <returns>
        /// The <see langword="Object"/> that contains the view state changes.
        /// </returns>
        public object SaveViewState()
        {
            if (_saveAll == true)
            {
                // Save all items.
                ArrayList states = new ArrayList(Count);
                for (int i = 0; i < Count; i++)
                {
                    ToolItem toolItem = (ToolItem)_items[i];
                    toolItem.SetDirty();
                    states.Add(((IStateManager)toolItem).SaveViewState());
                }
                if (states.Count > 0)
                {
                    return(states);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                // Save only the dirty items.
                ArrayList indices = new ArrayList();
                ArrayList states  = new ArrayList();

                for (int i = 0; i < Count; i++)
                {
                    ToolItem toolItem = (ToolItem)_items[i];
                    object   state    = ((IStateManager)toolItem).SaveViewState();
                    if (state != null)
                    {
                        states.Add(state);
                        indices.Add(i);
                    }
                }

                if (indices.Count > 0)
                {
                    return(new Pair(indices, states));
                }
            }

            return(null);
        }