Files
2026-06-04 11:42:34 +02:00

277 lines
12 KiB
C#

using System;
namespace System.Collections.Specialized
{
/// <summary>Implements IDictionary by using a <see cref="T:System.Collections.Specialized.ListDictionary" /> while the collection is small, and then switching to a <see cref="T:System.Collections.Hashtable" /> when the collection gets large.</summary>
// Token: 0x02000028 RID: 40
[Serializable]
public class HybridDictionary : ICollection, IDictionary, IEnumerable
{
/// <summary>Creates an empty case-sensitive <see cref="T:System.Collections.Specialized.HybridDictionary" />.</summary>
// Token: 0x06000193 RID: 403 RVA: 0x00006CF0 File Offset: 0x00004EF0
public HybridDictionary()
: this(0, false)
{
}
/// <summary>Creates an empty <see cref="T:System.Collections.Specialized.HybridDictionary" /> with the specified case sensitivity.</summary>
/// <param name="caseInsensitive">A Boolean that denotes whether the <see cref="T:System.Collections.Specialized.HybridDictionary" /> is case-insensitive. </param>
// Token: 0x06000194 RID: 404 RVA: 0x00006CFC File Offset: 0x00004EFC
public HybridDictionary(bool caseInsensitive)
: this(0, caseInsensitive)
{
}
/// <summary>Creates a case-sensitive <see cref="T:System.Collections.Specialized.HybridDictionary" /> with the specified initial size.</summary>
/// <param name="initialSize">The approximate number of entries that the <see cref="T:System.Collections.Specialized.HybridDictionary" /> can initially contain. </param>
// Token: 0x06000195 RID: 405 RVA: 0x00006D08 File Offset: 0x00004F08
public HybridDictionary(int initialSize)
: this(initialSize, false)
{
}
/// <summary>Creates a <see cref="T:System.Collections.Specialized.HybridDictionary" /> with the specified initial size and case sensitivity.</summary>
/// <param name="initialSize">The approximate number of entries that the <see cref="T:System.Collections.Specialized.HybridDictionary" /> can initially contain. </param>
/// <param name="caseInsensitive">A Boolean that denotes whether the <see cref="T:System.Collections.Specialized.HybridDictionary" /> is case-insensitive. </param>
// Token: 0x06000196 RID: 406 RVA: 0x00006D14 File Offset: 0x00004F14
public HybridDictionary(int initialSize, bool caseInsensitive)
{
this.caseInsensitive = caseInsensitive;
IComparer comparer = ((!caseInsensitive) ? null : CaseInsensitiveComparer.DefaultInvariant);
IHashCodeProvider hashCodeProvider = ((!caseInsensitive) ? null : CaseInsensitiveHashCodeProvider.DefaultInvariant);
if (initialSize <= 10)
{
this.list = new ListDictionary(comparer);
}
else
{
this.hashtable = new Hashtable(initialSize, hashCodeProvider, comparer);
}
}
/// <summary>Returns an <see cref="T:System.Collections.IEnumerator" /> that iterates through the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</summary>
/// <returns>An <see cref="T:System.Collections.IEnumerator" /> for the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</returns>
// Token: 0x06000197 RID: 407 RVA: 0x00006D7C File Offset: 0x00004F7C
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
// Token: 0x17000068 RID: 104
// (get) Token: 0x06000198 RID: 408 RVA: 0x00006D84 File Offset: 0x00004F84
private IDictionary inner
{
get
{
IDictionary dictionary2;
if (this.list == null)
{
IDictionary dictionary = this.hashtable;
dictionary2 = dictionary;
}
else
{
dictionary2 = this.list;
}
return dictionary2;
}
}
/// <summary>Gets the number of key/value pairs contained in the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</summary>
/// <returns>The number of key/value pairs contained in the <see cref="T:System.Collections.Specialized.HybridDictionary" />.Retrieving the value of this property is an O(1) operation.</returns>
// Token: 0x17000069 RID: 105
// (get) Token: 0x06000199 RID: 409 RVA: 0x00006DB0 File Offset: 0x00004FB0
public int Count
{
get
{
return this.inner.Count;
}
}
/// <summary>Gets a value indicating whether the <see cref="T:System.Collections.Specialized.HybridDictionary" /> has a fixed size.</summary>
/// <returns>This property always returns false.</returns>
// Token: 0x1700006A RID: 106
// (get) Token: 0x0600019A RID: 410 RVA: 0x00006DC0 File Offset: 0x00004FC0
public bool IsFixedSize
{
get
{
return false;
}
}
/// <summary>Gets a value indicating whether the <see cref="T:System.Collections.Specialized.HybridDictionary" /> is read-only.</summary>
/// <returns>This property always returns false.</returns>
// Token: 0x1700006B RID: 107
// (get) Token: 0x0600019B RID: 411 RVA: 0x00006DC4 File Offset: 0x00004FC4
public bool IsReadOnly
{
get
{
return false;
}
}
/// <summary>Gets a value indicating whether the <see cref="T:System.Collections.Specialized.HybridDictionary" /> is synchronized (thread safe).</summary>
/// <returns>This property always returns false.</returns>
// Token: 0x1700006C RID: 108
// (get) Token: 0x0600019C RID: 412 RVA: 0x00006DC8 File Offset: 0x00004FC8
public bool IsSynchronized
{
get
{
return false;
}
}
/// <summary>Gets or sets the value associated with the specified key.</summary>
/// <returns>The value associated with the specified key. If the specified key is not found, attempting to get it returns null, and attempting to set it creates a new entry using the specified key.</returns>
/// <param name="key">The key whose value to get or set. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="key" /> is null. </exception>
// Token: 0x1700006D RID: 109
public object this[object key]
{
get
{
return this.inner[key];
}
set
{
this.inner[key] = value;
if (this.list != null && this.Count > 10)
{
this.Switch();
}
}
}
/// <summary>Gets an <see cref="T:System.Collections.ICollection" /> containing the keys in the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</summary>
/// <returns>An <see cref="T:System.Collections.ICollection" /> containing the keys in the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</returns>
// Token: 0x1700006E RID: 110
// (get) Token: 0x0600019F RID: 415 RVA: 0x00006E0C File Offset: 0x0000500C
public ICollection Keys
{
get
{
return this.inner.Keys;
}
}
/// <summary>Gets an object that can be used to synchronize access to the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</summary>
/// <returns>An object that can be used to synchronize access to the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</returns>
// Token: 0x1700006F RID: 111
// (get) Token: 0x060001A0 RID: 416 RVA: 0x00006E1C File Offset: 0x0000501C
public object SyncRoot
{
get
{
return this;
}
}
/// <summary>Gets an <see cref="T:System.Collections.ICollection" /> containing the values in the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</summary>
/// <returns>An <see cref="T:System.Collections.ICollection" /> containing the values in the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</returns>
// Token: 0x17000070 RID: 112
// (get) Token: 0x060001A1 RID: 417 RVA: 0x00006E20 File Offset: 0x00005020
public ICollection Values
{
get
{
return this.inner.Values;
}
}
/// <summary>Adds an entry with the specified key and value into the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</summary>
/// <param name="key">The key of the entry to add. </param>
/// <param name="value">The value of the entry to add. The value can be null. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="key" /> is null. </exception>
/// <exception cref="T:System.ArgumentException">An entry with the same key already exists in the <see cref="T:System.Collections.Specialized.HybridDictionary" />. </exception>
// Token: 0x060001A2 RID: 418 RVA: 0x00006E30 File Offset: 0x00005030
public void Add(object key, object value)
{
this.inner.Add(key, value);
if (this.list != null && this.Count > 10)
{
this.Switch();
}
}
/// <summary>Removes all entries from the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</summary>
// Token: 0x060001A3 RID: 419 RVA: 0x00006E60 File Offset: 0x00005060
public void Clear()
{
this.inner.Clear();
}
/// <summary>Determines whether the <see cref="T:System.Collections.Specialized.HybridDictionary" /> contains a specific key.</summary>
/// <returns>true if the <see cref="T:System.Collections.Specialized.HybridDictionary" /> contains an entry with the specified key; otherwise, false.</returns>
/// <param name="key">The key to locate in the <see cref="T:System.Collections.Specialized.HybridDictionary" />. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="key" /> is null. </exception>
// Token: 0x060001A4 RID: 420 RVA: 0x00006E70 File Offset: 0x00005070
public bool Contains(object key)
{
return this.inner.Contains(key);
}
/// <summary>Copies the <see cref="T:System.Collections.Specialized.HybridDictionary" /> entries to a one-dimensional <see cref="T:System.Array" /> instance at the specified index.</summary>
/// <param name="array">The one-dimensional <see cref="T:System.Array" /> that is the destination of the <see cref="T:System.Collections.DictionaryEntry" /> objects copied from <see cref="T:System.Collections.Specialized.HybridDictionary" />. The <see cref="T:System.Array" /> must have zero-based indexing. </param>
/// <param name="index">The zero-based index in <paramref name="array" /> at which copying begins. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="array" /> is null. </exception>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="index" /> is less than zero. </exception>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="array" /> is multidimensional.-or- The number of elements in the source <see cref="T:System.Collections.Specialized.HybridDictionary" /> is greater than the available space from <paramref name="index" /> to the end of the destination <paramref name="array" />. </exception>
/// <exception cref="T:System.InvalidCastException">The type of the source <see cref="T:System.Collections.Specialized.HybridDictionary" /> cannot be cast automatically to the type of the destination <paramref name="array" />. </exception>
// Token: 0x060001A5 RID: 421 RVA: 0x00006E80 File Offset: 0x00005080
public void CopyTo(Array array, int index)
{
this.inner.CopyTo(array, index);
}
/// <summary>Returns an <see cref="T:System.Collections.IDictionaryEnumerator" /> that iterates through the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</summary>
/// <returns>An <see cref="T:System.Collections.IDictionaryEnumerator" /> for the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</returns>
// Token: 0x060001A6 RID: 422 RVA: 0x00006E90 File Offset: 0x00005090
public IDictionaryEnumerator GetEnumerator()
{
return this.inner.GetEnumerator();
}
/// <summary>Removes the entry with the specified key from the <see cref="T:System.Collections.Specialized.HybridDictionary" />.</summary>
/// <param name="key">The key of the entry to remove. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="key" /> is null. </exception>
// Token: 0x060001A7 RID: 423 RVA: 0x00006EA0 File Offset: 0x000050A0
public void Remove(object key)
{
this.inner.Remove(key);
}
// Token: 0x060001A8 RID: 424 RVA: 0x00006EB0 File Offset: 0x000050B0
private void Switch()
{
IComparer comparer = ((!this.caseInsensitive) ? null : CaseInsensitiveComparer.DefaultInvariant);
IHashCodeProvider hashCodeProvider = ((!this.caseInsensitive) ? null : CaseInsensitiveHashCodeProvider.DefaultInvariant);
this.hashtable = new Hashtable(this.list, hashCodeProvider, comparer);
this.list.Clear();
this.list = null;
}
// Token: 0x04000082 RID: 130
private const int switchAfter = 10;
// Token: 0x04000083 RID: 131
private bool caseInsensitive;
// Token: 0x04000084 RID: 132
private Hashtable hashtable;
// Token: 0x04000085 RID: 133
private ListDictionary list;
}
}