ParameterCollection.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / MS / Internal / Data / ParameterCollection.cs / 1 / ParameterCollection.cs

                            //---------------------------------------------------------------------------- 
//
// 
//    Copyright (C) Microsoft Corporation.  All rights reserved.
//  
//
// Description: ParameterCollection with a simple change notification callback 
//              and can be made Read-Only.  Created for ObjectDataProvider. 
//
//--------------------------------------------------------------------------- 

using System;
using System.Collections;   // IList
using System.Collections.ObjectModel;   // Collection 
using System.Windows;   // SR
 
namespace MS.Internal.Data 
{
    internal class ParameterCollection : Collection, IList 
    {
        //-----------------------------------------------------
        //
        //  Constructors 
        //
        //----------------------------------------------------- 
 
        #region Constructors
 
        public ParameterCollection(ParameterCollectionChanged parametersChanged)
            : base()
        {
            _parametersChanged = parametersChanged; 
        }
 
        #endregion Constructors 

        //------------------------------------------------------ 
        //
        //  Interface Properties
        //
        //----------------------------------------------------- 

        #region Interface Properties 
 
        bool IList.IsReadOnly
        { 
            get
            {
                return this.IsReadOnly;
            } 
        }
 
        bool IList.IsFixedSize 
        {
            get 
            {
                return this.IsFixedSize;
            }
        } 

        #endregion Interface Properties 
 
        //------------------------------------------------------
        // 
        //  Protected Methods
        //
        //------------------------------------------------------
 
        #region Protected Methods
 
        // Methods 

        protected override void ClearItems() 
        {
            CheckReadOnly();
            base.ClearItems();
            OnCollectionChanged(); 
        }
 
        protected override void InsertItem(int index, object value) 
        {
            CheckReadOnly(); 
            base.InsertItem(index, value);
            OnCollectionChanged();
        }
 
        protected override void RemoveItem(int index)
        { 
            CheckReadOnly(); 
            base.RemoveItem(index);
            OnCollectionChanged(); 
        }

        protected override void SetItem(int index, object value)
        { 
            CheckReadOnly();
            base.SetItem(index, value); 
            OnCollectionChanged(); 
        }
 
        #endregion Protected Methods

        //-----------------------------------------------------
        // 
        //  Protected Properties
        // 
        //------------------------------------------------------ 

        #region Protected Properties 

        protected virtual bool IsReadOnly
        {
            get 
            {
                return _isReadOnly; 
            } 
            set
            { 
                _isReadOnly = value;
            }
        }
 
        protected bool IsFixedSize
        { 
            get 
            {
                return this.IsReadOnly; 
            }
        }

        #endregion Protected Properties 

        //----------------------------------------------------- 
        // 
        //  Internal Methods
        // 
        //-----------------------------------------------------

        #region Internal Methods
 
        /// 
        /// sets whether the collection is read-only 
        ///  
        internal void SetReadOnly(bool isReadOnly)
        { 
            this.IsReadOnly = isReadOnly;
        }

        ///  
        /// silently clear the list.
        ///  
        ///  
        /// this internal method is not affected by the state of IsReadOnly.
        ///  
        internal void ClearInternal()
        {
            base.ClearItems();
        } 

        #endregion Internal Methods 
 
        //-----------------------------------------------------
        // 
        //  Private Methods
        //
        //------------------------------------------------------
 
        #region Private Methods
 
        private void CheckReadOnly() 
        {
            if (this.IsReadOnly) 
            {
                throw new InvalidOperationException(SR.Get(SRID.ObjectDataProviderParameterCollectionIsNotInUse));
            }
        } 

        ///  
        /// notify ObjectDataProvider that the parameters have changed 
        /// 
        private void OnCollectionChanged() 
        {
            _parametersChanged(this);
        }
 
        #endregion Private Methods
 
        //----------------------------------------------------- 
        //
        //  Private Fields 
        //
        //------------------------------------------------------

        #region Private Fields 

        private bool _isReadOnly = false; 
        private ParameterCollectionChanged _parametersChanged; 

        #endregion Private Fields 
    }

    internal delegate void ParameterCollectionChanged(ParameterCollection parameters);
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------------------- 
//
// 
//    Copyright (C) Microsoft Corporation.  All rights reserved.
//  
//
// Description: ParameterCollection with a simple change notification callback 
//              and can be made Read-Only.  Created for ObjectDataProvider. 
//
//--------------------------------------------------------------------------- 

using System;
using System.Collections;   // IList
using System.Collections.ObjectModel;   // Collection 
using System.Windows;   // SR
 
namespace MS.Internal.Data 
{
    internal class ParameterCollection : Collection, IList 
    {
        //-----------------------------------------------------
        //
        //  Constructors 
        //
        //----------------------------------------------------- 
 
        #region Constructors
 
        public ParameterCollection(ParameterCollectionChanged parametersChanged)
            : base()
        {
            _parametersChanged = parametersChanged; 
        }
 
        #endregion Constructors 

        //------------------------------------------------------ 
        //
        //  Interface Properties
        //
        //----------------------------------------------------- 

        #region Interface Properties 
 
        bool IList.IsReadOnly
        { 
            get
            {
                return this.IsReadOnly;
            } 
        }
 
        bool IList.IsFixedSize 
        {
            get 
            {
                return this.IsFixedSize;
            }
        } 

        #endregion Interface Properties 
 
        //------------------------------------------------------
        // 
        //  Protected Methods
        //
        //------------------------------------------------------
 
        #region Protected Methods
 
        // Methods 

        protected override void ClearItems() 
        {
            CheckReadOnly();
            base.ClearItems();
            OnCollectionChanged(); 
        }
 
        protected override void InsertItem(int index, object value) 
        {
            CheckReadOnly(); 
            base.InsertItem(index, value);
            OnCollectionChanged();
        }
 
        protected override void RemoveItem(int index)
        { 
            CheckReadOnly(); 
            base.RemoveItem(index);
            OnCollectionChanged(); 
        }

        protected override void SetItem(int index, object value)
        { 
            CheckReadOnly();
            base.SetItem(index, value); 
            OnCollectionChanged(); 
        }
 
        #endregion Protected Methods

        //-----------------------------------------------------
        // 
        //  Protected Properties
        // 
        //------------------------------------------------------ 

        #region Protected Properties 

        protected virtual bool IsReadOnly
        {
            get 
            {
                return _isReadOnly; 
            } 
            set
            { 
                _isReadOnly = value;
            }
        }
 
        protected bool IsFixedSize
        { 
            get 
            {
                return this.IsReadOnly; 
            }
        }

        #endregion Protected Properties 

        //----------------------------------------------------- 
        // 
        //  Internal Methods
        // 
        //-----------------------------------------------------

        #region Internal Methods
 
        /// 
        /// sets whether the collection is read-only 
        ///  
        internal void SetReadOnly(bool isReadOnly)
        { 
            this.IsReadOnly = isReadOnly;
        }

        ///  
        /// silently clear the list.
        ///  
        ///  
        /// this internal method is not affected by the state of IsReadOnly.
        ///  
        internal void ClearInternal()
        {
            base.ClearItems();
        } 

        #endregion Internal Methods 
 
        //-----------------------------------------------------
        // 
        //  Private Methods
        //
        //------------------------------------------------------
 
        #region Private Methods
 
        private void CheckReadOnly() 
        {
            if (this.IsReadOnly) 
            {
                throw new InvalidOperationException(SR.Get(SRID.ObjectDataProviderParameterCollectionIsNotInUse));
            }
        } 

        ///  
        /// notify ObjectDataProvider that the parameters have changed 
        /// 
        private void OnCollectionChanged() 
        {
            _parametersChanged(this);
        }
 
        #endregion Private Methods
 
        //----------------------------------------------------- 
        //
        //  Private Fields 
        //
        //------------------------------------------------------

        #region Private Fields 

        private bool _isReadOnly = false; 
        private ParameterCollectionChanged _parametersChanged; 

        #endregion Private Fields 
    }

    internal delegate void ParameterCollectionChanged(ParameterCollection parameters);
} 

// 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