⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nameobjectcollectionbase.cs

📁 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的
💻 CS
📖 第 1 页 / 共 2 页
字号:
			{				return ((Entry)(entries[index])).key;			}	// Determine if there a non-null keys in the collection.	protected bool BaseHasKeys()			{				Entry entry = table[GetHash(null)];				while(entry != null)				{					if(entry.key != null)					{						return true;					}					entry = entry.next;				}				return false;			}	// Remove all entries with a specific key.	protected void BaseRemove(String name)			{				if(readOnly)				{					throw new NotSupportedException(S._("NotSupp_ReadOnly"));				}				int hash = GetHash(name);				Entry entry = table[hash];				Entry prev = null;				while(entry != null)				{					if(Compare(entry.key, name))					{						if(prev != null)						{							prev.next = entry.next;						}						else						{							table[hash] = entry.next;						}						entry = entry.next;					}					else					{						prev = entry;						entry = entry.next;					}				}				int count = entries.Count;				int posn = 0;				while(posn < count)				{					if(Compare(((Entry)(entries[posn])).key, name))					{						entries.RemoveAt(posn);						--count;					}					else					{						++posn;					}				}			}	// Remove a specific entry by index.	protected void BaseRemoveAt(int index)			{				if(readOnly)				{					throw new NotSupportedException(S._("NotSupp_ReadOnly"));				}				Entry entry = (Entry)(entries[index]);				entries.RemoveAt(index);				int hash = GetHash(entry.key);				Entry find = table[hash];				Entry prev = null;				while(find != null)				{					if(find == entry)					{						if(prev != null)						{							prev.next = find.next;						}						else						{							table[hash] = find.next;						}						return;					}					else					{						prev = find;						find = find.next;					}				}			}	// Set the value of an entry at a particular index.	protected void BaseSet(int index, Object value)			{				if(readOnly)				{					throw new NotSupportedException(S._("NotSupp_ReadOnly"));				}				((Entry)(entries[index])).value = value;			}	// Set the value of the first entry with a particular name.	protected void BaseSet(String name, Object value)			{				if(readOnly)				{					throw new NotSupportedException(S._("NotSupp_ReadOnly"));				}				int hash = GetHash(name);				Entry entry = table[hash];				while(entry != null)				{					if(Compare(entry.key, name))					{						entry.value = value;						return;					}					entry = entry.next;				}				entry = new Entry(name, value);				entry.next = table[hash];				table[hash] = entry;				entries.Add(entry);			}	// Structure of an entry in the collection.	private class Entry	{		public String key;		public Object value;		public Entry  next;		// Constructor.		public Entry(String key, Object value)				{					this.key = key;					this.value = value;					this.next = null;				}	}; // class Entry	// Alternate interface to the keys in a name object collection.	public class KeysCollection : ICollection, IEnumerable	{		// Internal state.		private NameObjectCollectionBase c;		// Constructor.		internal KeysCollection(NameObjectCollectionBase c)				{					this.c = c;				}		// Implement the ICollection interface.		public int Count				{					get					{						return c.Count;					}				}		void ICollection.CopyTo(Array array, int index)				{					foreach(Object obj in this)					{						array.SetValue(obj, index);						++index;					}				}		bool ICollection.IsSynchronized				{					get					{						return false;					}				}		Object ICollection.SyncRoot				{					get					{						return c;					}				}		// Implement the IEnumerable interface.		public IEnumerator GetEnumerator()				{					return new KeysEnumerator(c);				}		// Get the key at a specific index.		public String Get(int index)				{					return c.BaseGetKey(index);				}		public String this[int index]				{					get					{						return Get(index);					}				}	}; // class KeysCollection	// Enumerator for the keys in a name object collection.	private class KeysEnumerator : IEnumerator	{		// Internal state.		private IEnumerator e;		// Constructor.		public KeysEnumerator(NameObjectCollectionBase c)				{					e = c.entries.GetEnumerator();				}		// Implement the IEnumerator interface.		bool IEnumerator.MoveNext()				{					return e.MoveNext();				}		void IEnumerator.Reset()				{					e.Reset();				}		Object IEnumerator.Current				{					get					{						return ((Entry)(e.Current)).key;					}				}	}; // class KeysEnumerator#if ECMA_COMPAT	// Local copy of "System.Collections.CaseInsenstiveHashCodeProvider"	// for use in ECMA-compatbile systems.	private class CaseInsensitiveHashCodeProvider : IHashCodeProvider	{		private static readonly CaseInsensitiveHashCodeProvider			defaultProvider = new CaseInsensitiveHashCodeProvider();		// Internal state.		private TextInfo info;		// Get the default comparer instance.		public static CaseInsensitiveHashCodeProvider Default				{					get					{						return defaultProvider;					}				}		// Constructors.		public CaseInsensitiveHashCodeProvider()				{					info = CultureInfo.CurrentCulture.TextInfo;				}		public CaseInsensitiveHashCodeProvider(CultureInfo culture)				{					if(culture == null)					{						throw new ArgumentNullException("culture");					}					info = culture.TextInfo;				}		// Implement the IHashCodeProvider interface.		public int GetHashCode(Object obj)				{					String str = (obj as String);					if(str != null)					{						return info.ToLower(str).GetHashCode();					}					else if(obj != null)					{						return obj.GetHashCode();					}					else					{						throw new ArgumentNullException("obj");					}				}	}; // class CaseInsensitiveHashCodeProvider	// Local copy of "System.Collections.CaseInsenstiveComparer"	// for use in ECMA-compatbile systems.	private class CaseInsensitiveComparer : IComparer	{		// The default case insensitive comparer instance.		private static readonly CaseInsensitiveComparer defaultComparer =			new CaseInsensitiveComparer();			// Internal state.		private CompareInfo compare;		// Get the default comparer instance.		public static CaseInsensitiveComparer Default				{					get					{						return defaultComparer;					}				}		// Constructors.		public CaseInsensitiveComparer()				{					compare = CultureInfo.CurrentCulture.CompareInfo;				}		public CaseInsensitiveComparer(CultureInfo culture)				{					if(culture == null)					{						throw new ArgumentNullException("culture");					}					compare = culture.CompareInfo;				}		// Implement the IComparer interface.		public int Compare(Object a, Object b)				{					String stra = (a as String);					String strb = (b as String);					if(stra != null && strb != null)					{						return compare.Compare							(stra, strb, CompareOptions.IgnoreCase);					}					else					{						return Comparer.Default.Compare(a, b);					}				}	}; // class CaseInsensitiveComparer#endif // ECMA_COMPAT}; // class NameObjectCollectionBase}; // namespace System.Collections.Specialized

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -