TableColumnCollectionInternal.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / documents / TableColumnCollectionInternal.cs / 1305600 / TableColumnCollectionInternal.cs

                            using MS.Utility; 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows; 
using System.Windows.Documents;
using System.Diagnostics; 
 
namespace MS.Internal.Documents
{ 
    /// 
    /// This class is specialization of  to be used for
    /// TableColumn collections
    ///  
    internal class TableColumnCollectionInternal : ContentElementCollection
    { 
        internal TableColumnCollectionInternal(Table owner) 
            : base(owner)
        { 

        }

        ///  
        /// Appends a TItem to the end of the ContentElementCollection.
        ///  
        /// The TItem to be added to the end of the ContentElementCollection. 
        /// The ContentElementCollection index at which the TItem has been added.
        /// Adding a null is prohibited. 
        /// 
        /// If the item value is null.
        /// 
        ///  
        /// If the new child already has a parent.
        ///  
        public override void Add(TableColumn item) 
        {
            Version++; 

            if (item == null)
            {
                throw new ArgumentNullException("item"); 
            }
            if (Size == Items.Length) 
            { 
                EnsureCapacity(Size + 1);
            } 

            int index = Size++;
            Debug.Assert(Items[index] == null);
 
            PrivateConnectChild(index, item);
        } 
 
        /// 
        /// Removes all elements from the ContentElementCollection. 
        /// 
        /// 
        /// Count is set to zero. Capacity remains unchanged.
        /// To reset the capacity of the ContentElementCollection, call TrimToSize 
        /// or set the Capacity property directly.
        ///  
        public override void Clear() 
        {
            Version++; 

            for (int i = 0; i < Size; ++i)
            {
                Debug.Assert(BelongsToOwner(Items[i])); 

                PrivateDisconnectChild(Items[i]); 
                Items[i] = null; 
            }
            Size = 0; 
        }
        /// 
        /// Inserts a TItem into the ContentElementCollection at the specified index.
        ///  
        /// The zero-based index at which value should be inserted.
        /// The TItem to insert.  
        ///  
        /// indexc> is less than zero.
        /// -or- 
        /// index is greater than Count.
        /// 
        /// 
        /// If the item value is null. 
        /// 
        ///  
        /// If Count already equals Capacity, the capacity of the 
        /// ContentElementCollection is increased before the new TItem is inserted.
        /// 
        /// If index is equal to Count, TItem is added to the
        /// end of ContentElementCollection.
        ///
        /// The TItems that follow the insertion point move down to 
        /// accommodate the new TItem. The indexes of the TItems that are
        /// moved are also updated. 
        ///  
        public override void Insert(int index, TableColumn item)
        { 
            Version++;

            if (index < 0 || index > Size)
            { 
                throw new ArgumentOutOfRangeException(SR.Get(SRID.TableCollectionOutOfRange));
            } 
            if (item == null) 
            {
                throw new ArgumentNullException("item"); 
            }
            if (Size == Items.Length)
            {
                EnsureCapacity(Size + 1); 
            }
 
            for (int i = Size - 1; i >= index; --i) 
            {
                Debug.Assert(BelongsToOwner(Items[i])); 

                Items[i + 1] = Items[i];
                Items[i].Index = i + 1;
            } 

            Items[index] = null; 
 
            Size++;
            PrivateConnectChild(index, item); 
        }
        /// 
        /// Sets the specified TItem at the specified index;
        /// Connects the item to the model tree; 
        /// Notifies the TItem about the event.
        ///  
        ///  
        /// If the new item has already a parent or if the slot at the specified index is not null.
        ///  
        /// 
        /// Note that the function requires that _item[index] == null and
        /// it also requires that the passed in item is not included into another ContentElementCollection.
        ///  
        internal override void PrivateConnectChild(int index, TableColumn item)
        { 
            Debug.Assert(item != null && item.Index == -1); 
            Debug.Assert(Items[index] == null);
 
            // If the TItem is already parented correctly through a proxy, there's no need
            // to change parentage.  Otherwise, it should be parented to Owner.
            if (item.Parent is DummyProxy)
            { 
                if (LogicalTreeHelper.GetParent(item.Parent) != Owner)
                { 
                    throw new System.ArgumentException(SR.Get(SRID.TableCollectionWrongProxyParent)); 
                }
            } 
            else
            {
                if (item.Parent != null)
                { 
                    throw new System.ArgumentException(SR.Get(SRID.TableCollectionInOtherCollection));
                } 
 
                Owner.AddLogicalChild(item);
            } 

            // add the item into collection's array
            Items[index] = item;
            item.Index = index; 

            // notify the TItem about the change 
            item.OnEnterParentTree(); 
        }
 
        /// 
        /// Notifies the TItem about the event;
        /// Disconnects the item from the model tree;
        /// Sets the TItem's slot in the collection's array to null. 
        /// 
        internal override void PrivateDisconnectChild(TableColumn item) 
        { 
            Debug.Assert(item != null);
 
            // notify the TItem about the change
            item.OnExitParentTree();

            // remove the item from collection's array 
            Items[item.Index] = null;
            item.Index = -1; 
 
            // remove from model tree
            // If the item is parented through a proxy then the parent link of the item is 
            // not to Owner and we should not change the parentage.
            DummyProxy proxy = item.Parent as DummyProxy;
            if (proxy == null)
            { 
                Owner.RemoveLogicalChild(item);
            } 
        } 
        /// 
        /// Removes the specified TItem from the ContentElementCollection. 
        /// 
        /// The TItem to remove from the ContentElementCollection.
        /// 
        /// If the item value is null. 
        /// 
        ///  
        /// If the specified TItem is not in this collection. 
        /// 
        ///  
        /// The TItems that follow the removed TItem move up to occupy
        /// the vacated spot. The indices of the TItems that are moved
        /// also updated.
        ///  
        public override bool Remove(TableColumn item)
        { 
            Version++; 

            if (item == null) 
            {
                throw new ArgumentNullException("item");
            }
            if (!BelongsToOwner(item)) 
            {
                return false; 
            } 

            PrivateRemove(item); 

            return true;
        }
 
        /// 
        /// Removes the TItem at the specified index. 
        ///  
        /// The zero-based index of the TItem to remove.
        ///  
        /// index is less than zero
        /// - or -
        /// index is equal or greater than count.
        ///  
        /// 
        /// The TItems that follow the removed TItem move up to occupy 
        /// the vacated spot. The indices of the TItems that are moved 
        /// also updated.
        ///  
        public override void RemoveAt(int index)
        {
            Version++;
 
            if (index < 0 || index >= Size)
            { 
                throw new ArgumentOutOfRangeException(SR.Get(SRID.TableCollectionOutOfRange)); 
            }
 
            PrivateRemove(Items[index]);
        }

 
        /// 
        /// Removes a range of TItems from the ContentElementCollection. 
        ///  
        /// The zero-based index of the range
        /// of TItems to remove 
        /// The number of TItems to remove.
        /// 
        /// index is less than zero.
        /// -or- 
        /// count is less than zero.
        ///  
        ///  
        /// index and count do not denote a valid range of TItems in the ContentElementCollection.
        ///  
        /// 
        /// The TItems that follow the removed TItems move up to occupy
        /// the vacated spot. The indices of the TItems that are moved are
        /// also updated. 
        /// 
        public override void RemoveRange(int index, int count) 
        { 
            Version++;
 
            if (index < 0 || index >= Size)
            {
                throw new ArgumentOutOfRangeException(SR.Get(SRID.TableCollectionOutOfRange));
            } 
            if (count < 0)
            { 
                throw new ArgumentOutOfRangeException(SR.Get(SRID.TableCollectionCountNeedNonNegNum)); 
            }
            if (Size - index < count) 
            {
                throw new ArgumentException(SR.Get(SRID.TableCollectionRangeOutOfRange));
            }
 
            if (count > 0)
            { 
                for (int i = index + count - 1; i >= index; --i) 
                {
                    Debug.Assert(BelongsToOwner(Items[i])); 

                    PrivateDisconnectChild(Items[i]);
                }
 
                Size -= count;
                for (int i = index; i < Size; ++i) 
                { 
                    Debug.Assert(BelongsToOwner(Items[i + count]));
 
                    Items[i] = Items[i + count];
                    Items[i].Index = i;
                    Items[i + count] = null;
                } 
            }
        } 
        ///  
        /// Indexer for the ContentElementCollection. Gets the TItem stored at the
        /// zero-based index of the ContentElementCollection. 
        /// 
        /// This property provides the ability to access a specific TItem in the
        /// ContentElementCollection by using the following systax: TItem myTItem = myContentElementCollection[index].
        ///  
        /// 
        /// index is less than zero -or- index is equal to or greater than Count. 
        ///  
        public override TableColumn this[int index]
        { 
            get
            {

                if (index < 0 || index >= Size) 
                {
                    throw new ArgumentOutOfRangeException(SR.Get(SRID.TableCollectionOutOfRange)); 
                } 
                return (Items[index]);
            } 
            set
            {
                if (index < 0 || index >= Size)
                { 
                    throw new ArgumentOutOfRangeException(SR.Get(SRID.TableCollectionOutOfRange));
                } 
 
                if (value == null)
                { 
                    throw new ArgumentNullException("value");
                }

                PrivateDisconnectChild(Items[index]); 
                PrivateConnectChild(index, value);
            } 
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK