DataBindingCollection.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 / whidbey / NetFxQFE / ndp / fx / src / xsp / System / Web / UI / DataBindingCollection.cs / 1 / DataBindingCollection.cs

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

namespace System.Web.UI { 
 
    using System;
    using System.Collections; 
    using System.Collections.Specialized;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Data; 
    using System.Web.Util;
    using System.Security.Permissions; 
 

    ///  
    /// 
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    public sealed class DataBindingCollection : ICollection {
        private EventHandler changedEvent; 

        private Hashtable bindings; 
        private Hashtable removedBindings; 

 
        /// 
        /// 
        public DataBindingCollection() {
            this.bindings = new Hashtable(StringComparer.OrdinalIgnoreCase); 
        }
 
 
        /// 
        ///  
        public int Count {
            get {
                return bindings.Count;
            } 
        }
 
 
        /// 
        ///  
        public bool IsReadOnly {
            get {
                return false;
            } 
        }
 
 
        /// 
        ///  
        public bool IsSynchronized {
            get {
                return false;
            } 
        }
 
 
        /// 
        ///  
        public string[] RemovedBindings {
            get {
                int bindingCount = 0;
                ICollection keys = null; 

                if (removedBindings != null) { 
                    keys = removedBindings.Keys; 
                    bindingCount = keys.Count;
 
                    string[] removedNames = new string[bindingCount];
                    int i = 0;

                    foreach (string s in keys) { 
                        removedNames[i++] = s;
                    } 
 
                    removedBindings.Clear();
                    return removedNames; 
                }
                else {
                    return new string[0];
                } 
            }
        } 
 

        ///  
        /// 
        private Hashtable RemovedBindingsTable {
            get {
                if (removedBindings == null) { 
                    removedBindings = new Hashtable(StringComparer.OrdinalIgnoreCase);
                } 
                return removedBindings; 
            }
        } 


        /// 
        ///  
        public object SyncRoot {
            get { 
                return this; 
            }
        } 


        /// 
        ///  
        public DataBinding this[string propertyName] {
            get { 
                object o = bindings[propertyName]; 
                if (o != null)
                    return(DataBinding)o; 
                return null;
            }
        }
 

        public event EventHandler Changed { 
            add { 
                changedEvent = (EventHandler)Delegate.Combine(changedEvent, value);
            } 
            remove {
                changedEvent = (EventHandler)Delegate.Remove(changedEvent, value);
            }
        } 

 
 
        /// 
        ///  
        public void Add(DataBinding binding) {
            bindings[binding.PropertyName] = binding;
            RemovedBindingsTable.Remove(binding.PropertyName);
 
            OnChanged();
        } 
 

        ///  
        /// 
        public bool Contains(string propertyName) {
            return bindings.Contains(propertyName);
        } 

 
        ///  
        /// 
        public void Clear() { 
            ICollection keys = bindings.Keys;
            if ((keys.Count != 0) && (removedBindings == null)) {
                // ensure the removedBindings hashtable is created
                Hashtable h = RemovedBindingsTable; 
            }
            foreach (string s in keys) { 
                removedBindings[s] = String.Empty; 
            }
 
            bindings.Clear();

            OnChanged();
        } 

 
        ///  
        /// 
        public void CopyTo(Array array, int index) { 
            for (IEnumerator e = this.GetEnumerator(); e.MoveNext();)
                array.SetValue(e.Current, index++);
        }
 

        ///  
        ///  
        public IEnumerator GetEnumerator() {
            return bindings.Values.GetEnumerator(); 
        }

        private void OnChanged() {
            if (changedEvent != null) { 
                changedEvent(this, EventArgs.Empty);
            } 
        } 

 
        /// 
        /// 
        public void Remove(string propertyName) {
            Remove(propertyName, true); 
        }
 
 
        /// 
        ///  
        public void Remove(DataBinding binding) {
            Remove(binding.PropertyName, true);
        }
 

        ///  
        ///  
        public void Remove(string propertyName, bool addToRemovedList) {
            if (Contains(propertyName)) { 
                bindings.Remove(propertyName);
                if (addToRemovedList) {
                    RemovedBindingsTable[propertyName] = String.Empty;
                } 

                OnChanged(); 
            } 
        }
    } 
}


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

namespace System.Web.UI { 
 
    using System;
    using System.Collections; 
    using System.Collections.Specialized;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Data; 
    using System.Web.Util;
    using System.Security.Permissions; 
 

    ///  
    /// 
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    public sealed class DataBindingCollection : ICollection {
        private EventHandler changedEvent; 

        private Hashtable bindings; 
        private Hashtable removedBindings; 

 
        /// 
        /// 
        public DataBindingCollection() {
            this.bindings = new Hashtable(StringComparer.OrdinalIgnoreCase); 
        }
 
 
        /// 
        ///  
        public int Count {
            get {
                return bindings.Count;
            } 
        }
 
 
        /// 
        ///  
        public bool IsReadOnly {
            get {
                return false;
            } 
        }
 
 
        /// 
        ///  
        public bool IsSynchronized {
            get {
                return false;
            } 
        }
 
 
        /// 
        ///  
        public string[] RemovedBindings {
            get {
                int bindingCount = 0;
                ICollection keys = null; 

                if (removedBindings != null) { 
                    keys = removedBindings.Keys; 
                    bindingCount = keys.Count;
 
                    string[] removedNames = new string[bindingCount];
                    int i = 0;

                    foreach (string s in keys) { 
                        removedNames[i++] = s;
                    } 
 
                    removedBindings.Clear();
                    return removedNames; 
                }
                else {
                    return new string[0];
                } 
            }
        } 
 

        ///  
        /// 
        private Hashtable RemovedBindingsTable {
            get {
                if (removedBindings == null) { 
                    removedBindings = new Hashtable(StringComparer.OrdinalIgnoreCase);
                } 
                return removedBindings; 
            }
        } 


        /// 
        ///  
        public object SyncRoot {
            get { 
                return this; 
            }
        } 


        /// 
        ///  
        public DataBinding this[string propertyName] {
            get { 
                object o = bindings[propertyName]; 
                if (o != null)
                    return(DataBinding)o; 
                return null;
            }
        }
 

        public event EventHandler Changed { 
            add { 
                changedEvent = (EventHandler)Delegate.Combine(changedEvent, value);
            } 
            remove {
                changedEvent = (EventHandler)Delegate.Remove(changedEvent, value);
            }
        } 

 
 
        /// 
        ///  
        public void Add(DataBinding binding) {
            bindings[binding.PropertyName] = binding;
            RemovedBindingsTable.Remove(binding.PropertyName);
 
            OnChanged();
        } 
 

        ///  
        /// 
        public bool Contains(string propertyName) {
            return bindings.Contains(propertyName);
        } 

 
        ///  
        /// 
        public void Clear() { 
            ICollection keys = bindings.Keys;
            if ((keys.Count != 0) && (removedBindings == null)) {
                // ensure the removedBindings hashtable is created
                Hashtable h = RemovedBindingsTable; 
            }
            foreach (string s in keys) { 
                removedBindings[s] = String.Empty; 
            }
 
            bindings.Clear();

            OnChanged();
        } 

 
        ///  
        /// 
        public void CopyTo(Array array, int index) { 
            for (IEnumerator e = this.GetEnumerator(); e.MoveNext();)
                array.SetValue(e.Current, index++);
        }
 

        ///  
        ///  
        public IEnumerator GetEnumerator() {
            return bindings.Values.GetEnumerator(); 
        }

        private void OnChanged() {
            if (changedEvent != null) { 
                changedEvent(this, EventArgs.Empty);
            } 
        } 

 
        /// 
        /// 
        public void Remove(string propertyName) {
            Remove(propertyName, true); 
        }
 
 
        /// 
        ///  
        public void Remove(DataBinding binding) {
            Remove(binding.PropertyName, true);
        }
 

        ///  
        ///  
        public void Remove(string propertyName, bool addToRemovedList) {
            if (Contains(propertyName)) { 
                bindings.Remove(propertyName);
                if (addToRemovedList) {
                    RemovedBindingsTable[propertyName] = String.Empty;
                } 

                OnChanged(); 
            } 
        }
    } 
}


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