DataKeyArray.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 / ndp / fx / src / xsp / System / Web / UI / WebControls / DataKeyArray.cs / 1305376 / DataKeyArray.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Web.UI.WebControls { 
 
    using System;
    using System.Collections; 

    /// 
    /// 
    public sealed class DataKeyArray : ICollection, IStateManager { 

        private ArrayList _keys; 
        private bool _isTracking; 

 
        /// 
        /// Initializes a new instance of the  class.
        /// 
        public DataKeyArray(ArrayList keys) { 
            this._keys = keys;
        } 
 

        ///  
        ///    Gets the number of objects in the collection. This property is read-only.
        /// 
        public int Count {
            get { 
                return _keys.Count;
            } 
        } 

 
        /// 
        /// Gets the value that specifies whether items in the  can be
        ///    modified. This property is read-only.
        ///  
        public bool IsReadOnly {
            get { 
                return false; 
            }
        } 


        /// 
        /// Gets a value that indicates whether the  is 
        ///    thread-safe. This property is read-only.
        ///  
        public bool IsSynchronized { 
            get {
                return false; 
            }
        }

 
        /// 
        ///    Gets the object used to synchronize access to the collection. This property is read-only.  
        ///  
        public object SyncRoot {
            get { 
                return this;
            }
        }
 

        ///  
        /// Gets a  at the specified index in the collection. This property is read-only. 
        /// 
        public DataKey this[int index] { 
            get {
                return _keys[index] as DataKey;
            }
        } 

 
 
        /// 
        /// Copies the contents of the entire collection into an  appending at 
        ///    the specified index of the .
        /// 
        public void CopyTo(DataKey[] array, int index) {
            ((ICollection)this).CopyTo(array, index); 
        }
 
 
        /// 
        void ICollection.CopyTo(Array array, int index) { 
            for (IEnumerator e = this.GetEnumerator(); e.MoveNext();)
                array.SetValue(e.Current, index++);
        }
 

        ///  
        /// Creates an enumerator for the  used to iterate 
        ///    through the collection.
        ///  
        public IEnumerator GetEnumerator() {
            return _keys.GetEnumerator();
        }
 
        #region IStateManager implementation
 
        ///  
        bool IStateManager.IsTrackingViewState {
            get { 
                return _isTracking;
            }
        }
 

        ///  
        void IStateManager.LoadViewState(object state) { 
            if (state != null) {
                object[] keysState = (object[])state; 

                for (int i = 0; i < keysState.Length; i++) {
                    if (keysState[i] != null) {
                        ((IStateManager)_keys[i]).LoadViewState(keysState[i]); 
                    }
                } 
            } 
        }
 

        /// 
        object IStateManager.SaveViewState() {
            int keyCount = _keys.Count; 
            object[] keysState = new object[keyCount];
            bool savedState = false; 
 
            for (int i = 0; i < keyCount; i++) {
                keysState[i] = ((IStateManager)_keys[i]).SaveViewState(); 
                if (keysState[i] != null)
                    savedState = true;
            }
 
            return savedState ? keysState : null;
        } 
 

        ///  
        void IStateManager.TrackViewState() {
            _isTracking = true;

            int keyCount = _keys.Count; 
            for (int i = 0; i < keyCount; i++) {
                ((IStateManager)_keys[i]).TrackViewState(); 
            } 
        }
        #endregion 
    }
}


// File provided for Reference Use Only by Microsoft Corporation (c) 2007.


                        

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