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

502 lines
24 KiB
C#

using System;
using System.Runtime.Serialization;
using System.Text;
namespace System.Collections.Specialized
{
/// <summary>Represents a collection of associated <see cref="T:System.String" /> keys and <see cref="T:System.String" /> values that can be accessed either with the key or with the index. </summary>
// Token: 0x02000033 RID: 51
[Serializable]
public class NameValueCollection : NameObjectCollectionBase
{
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.Specialized.NameValueCollection" /> class that is empty, has the default initial capacity and uses the default case-insensitive hash code provider and the default case-insensitive comparer.</summary>
// Token: 0x06000209 RID: 521 RVA: 0x000080C0 File Offset: 0x000062C0
public NameValueCollection()
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.Specialized.NameValueCollection" /> class that is empty, has the specified initial capacity and uses the default case-insensitive hash code provider and the default case-insensitive comparer.</summary>
/// <param name="capacity">The initial number of entries that the <see cref="T:System.Collections.Specialized.NameValueCollection" /> can contain.</param>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="capacity" /> is less than zero.</exception>
// Token: 0x0600020A RID: 522 RVA: 0x000080C8 File Offset: 0x000062C8
public NameValueCollection(int capacity)
: base(capacity)
{
}
/// <summary>Copies the entries from the specified <see cref="T:System.Collections.Specialized.NameValueCollection" /> to a new <see cref="T:System.Collections.Specialized.NameValueCollection" /> with the same initial capacity as the number of entries copied and using the same hash code provider and the same comparer as the source collection.</summary>
/// <param name="col">The <see cref="T:System.Collections.Specialized.NameValueCollection" /> to copy to the new <see cref="T:System.Collections.Specialized.NameValueCollection" /> instance.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="col" /> is null.</exception>
// Token: 0x0600020B RID: 523 RVA: 0x000080D4 File Offset: 0x000062D4
public NameValueCollection(NameValueCollection col)
{
IEqualityComparer equalityComparer2;
if (col == null)
{
IEqualityComparer equalityComparer = null;
equalityComparer2 = equalityComparer;
}
else
{
equalityComparer2 = col.EqualityComparer;
}
IComparer comparer2;
if (col == null)
{
IComparer comparer = null;
comparer2 = comparer;
}
else
{
comparer2 = col.Comparer;
}
IHashCodeProvider hashCodeProvider2;
if (col == null)
{
IHashCodeProvider hashCodeProvider = null;
hashCodeProvider2 = hashCodeProvider;
}
else
{
hashCodeProvider2 = col.HashCodeProvider;
}
base..ctor(equalityComparer2, comparer2, hashCodeProvider2);
if (col == null)
{
throw new ArgumentNullException("col");
}
this.Add(col);
}
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.Specialized.NameValueCollection" /> class that is empty, has the default initial capacity and uses the specified hash code provider and the specified comparer.</summary>
/// <param name="hashProvider">The <see cref="T:System.Collections.IHashCodeProvider" /> that will supply the hash codes for all keys in the <see cref="T:System.Collections.Specialized.NameValueCollection" />.</param>
/// <param name="comparer">The <see cref="T:System.Collections.IComparer" /> to use to determine whether two keys are equal.</param>
// Token: 0x0600020C RID: 524 RVA: 0x0000813C File Offset: 0x0000633C
[Obsolete("Use NameValueCollection (IEqualityComparer)")]
public NameValueCollection(IHashCodeProvider hashProvider, IComparer comparer)
: base(hashProvider, comparer)
{
}
/// <summary>Copies the entries from the specified <see cref="T:System.Collections.Specialized.NameValueCollection" /> to a new <see cref="T:System.Collections.Specialized.NameValueCollection" /> with the specified initial capacity or the same initial capacity as the number of entries copied, whichever is greater, and using the default case-insensitive hash code provider and the default case-insensitive comparer.</summary>
/// <param name="capacity">The initial number of entries that the <see cref="T:System.Collections.Specialized.NameValueCollection" /> can contain.</param>
/// <param name="col">The <see cref="T:System.Collections.Specialized.NameValueCollection" /> to copy to the new <see cref="T:System.Collections.Specialized.NameValueCollection" /> instance.</param>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="capacity" /> is less than zero.</exception>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="col" /> is null.</exception>
// Token: 0x0600020D RID: 525 RVA: 0x00008148 File Offset: 0x00006348
public NameValueCollection(int capacity, NameValueCollection col)
{
IHashCodeProvider hashCodeProvider2;
if (col == null)
{
IHashCodeProvider hashCodeProvider = null;
hashCodeProvider2 = hashCodeProvider;
}
else
{
hashCodeProvider2 = col.HashCodeProvider;
}
IComparer comparer2;
if (col == null)
{
IComparer comparer = null;
comparer2 = comparer;
}
else
{
comparer2 = col.Comparer;
}
base..ctor(capacity, hashCodeProvider2, comparer2);
this.Add(col);
}
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.Specialized.NameValueCollection" /> class that is serializable and uses the specified <see cref="T:System.Runtime.Serialization.SerializationInfo" /> and <see cref="T:System.Runtime.Serialization.StreamingContext" />.</summary>
/// <param name="info">A <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object that contains the information required to serialize the new <see cref="T:System.Collections.Specialized.NameValueCollection" /> instance.</param>
/// <param name="context">A <see cref="T:System.Runtime.Serialization.StreamingContext" /> object that contains the source and destination of the serialized stream associated with the new <see cref="T:System.Collections.Specialized.NameValueCollection" /> instance.</param>
// Token: 0x0600020E RID: 526 RVA: 0x0000818C File Offset: 0x0000638C
protected NameValueCollection(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.Specialized.NameValueCollection" /> class that is empty, has the specified initial capacity and uses the specified hash code provider and the specified comparer.</summary>
/// <param name="capacity">The initial number of entries that the <see cref="T:System.Collections.Specialized.NameValueCollection" /> can contain.</param>
/// <param name="hashProvider">The <see cref="T:System.Collections.IHashCodeProvider" /> that will supply the hash codes for all keys in the <see cref="T:System.Collections.Specialized.NameValueCollection" />.</param>
/// <param name="comparer">The <see cref="T:System.Collections.IComparer" /> to use to determine whether two keys are equal.</param>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="capacity" /> is less than zero.</exception>
// Token: 0x0600020F RID: 527 RVA: 0x00008198 File Offset: 0x00006398
[Obsolete("Use NameValueCollection (IEqualityComparer)")]
public NameValueCollection(int capacity, IHashCodeProvider hashProvider, IComparer comparer)
: base(capacity, hashProvider, comparer)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.Specialized.NameValueCollection" /> class that is empty, has the default initial capacity, and uses the specified <see cref="T:System.Collections.IEqualityComparer" /> object.</summary>
/// <param name="equalityComparer">The <see cref="T:System.Collections.IEqualityComparer" /> object to use to determine whether two keys are equal and to generate hash codes for the keys in the collection.</param>
// Token: 0x06000210 RID: 528 RVA: 0x000081A4 File Offset: 0x000063A4
public NameValueCollection(IEqualityComparer equalityComparer)
: base(equalityComparer)
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.Specialized.NameValueCollection" /> class that is empty, has the specified initial capacity, and uses the specified <see cref="T:System.Collections.IEqualityComparer" /> object.</summary>
/// <param name="capacity">The initial number of entries that the <see cref="T:System.Collections.Specialized.NameValueCollection" /> object can contain.</param>
/// <param name="equalityComparer">The <see cref="T:System.Collections.IEqualityComparer" /> object to use to determine whether two keys are equal and to generate hash codes for the keys in the collection.</param>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="capacity" /> is less than zero.</exception>
// Token: 0x06000211 RID: 529 RVA: 0x000081B0 File Offset: 0x000063B0
public NameValueCollection(int capacity, IEqualityComparer equalityComparer)
: base(capacity, equalityComparer)
{
}
/// <summary>Gets all the keys in the <see cref="T:System.Collections.Specialized.NameValueCollection" />.</summary>
/// <returns>A <see cref="T:System.String" /> array that contains all the keys of the <see cref="T:System.Collections.Specialized.NameValueCollection" />.</returns>
// Token: 0x17000090 RID: 144
// (get) Token: 0x06000212 RID: 530 RVA: 0x000081BC File Offset: 0x000063BC
public virtual string[] AllKeys
{
get
{
if (this.cachedAllKeys == null)
{
this.cachedAllKeys = base.BaseGetAllKeys();
}
return this.cachedAllKeys;
}
}
/// <summary>Gets the entry at the specified index of the <see cref="T:System.Collections.Specialized.NameValueCollection" />.</summary>
/// <returns>A <see cref="T:System.String" /> that contains the comma-separated list of values at the specified index of the collection.</returns>
/// <param name="index">The zero-based index of the entry to locate in the collection.</param>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="index" /> is outside the valid range of indexes for the collection.</exception>
// Token: 0x17000091 RID: 145
public string this[int index]
{
get
{
return this.Get(index);
}
}
/// <summary>Gets or sets the entry with the specified key in the <see cref="T:System.Collections.Specialized.NameValueCollection" />.</summary>
/// <returns>A <see cref="T:System.String" /> that contains the comma-separated list of values associated with the specified key, if found; otherwise, null.</returns>
/// <param name="name">The <see cref="T:System.String" /> key of the entry to locate. The key can be null.</param>
/// <exception cref="T:System.NotSupportedException">The collection is read-only and the operation attempts to modify the collection. </exception>
// Token: 0x17000092 RID: 146
public string this[string name]
{
get
{
return this.Get(name);
}
set
{
this.Set(name, value);
}
}
/// <summary>Copies the entries in the specified <see cref="T:System.Collections.Specialized.NameValueCollection" /> to the current <see cref="T:System.Collections.Specialized.NameValueCollection" />.</summary>
/// <param name="c">The <see cref="T:System.Collections.Specialized.NameValueCollection" /> to copy to the current <see cref="T:System.Collections.Specialized.NameValueCollection" />.</param>
/// <exception cref="T:System.NotSupportedException">The collection is read-only.</exception>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="c" /> is null.</exception>
// Token: 0x06000216 RID: 534 RVA: 0x00008200 File Offset: 0x00006400
public void Add(NameValueCollection c)
{
if (base.IsReadOnly)
{
throw new NotSupportedException("Collection is read-only");
}
if (c == null)
{
throw new ArgumentNullException("c");
}
this.InvalidateCachedArrays();
int count = c.Count;
for (int i = 0; i < count; i++)
{
string key = c.GetKey(i);
ArrayList arrayList = (ArrayList)c.BaseGet(i);
ArrayList arrayList2 = (ArrayList)base.BaseGet(key);
if (arrayList2 != null && arrayList != null)
{
arrayList2.AddRange(arrayList);
}
else if (arrayList != null)
{
arrayList2 = new ArrayList(arrayList);
}
base.BaseSet(key, arrayList2);
}
}
/// <summary>Adds an entry with the specified name and value to the <see cref="T:System.Collections.Specialized.NameValueCollection" />.</summary>
/// <param name="name">The <see cref="T:System.String" /> key of the entry to add. The key can be null.</param>
/// <param name="value">The <see cref="T:System.String" /> value of the entry to add. The value can be null.</param>
/// <exception cref="T:System.NotSupportedException">The collection is read-only. </exception>
// Token: 0x06000217 RID: 535 RVA: 0x000082A8 File Offset: 0x000064A8
public virtual void Add(string name, string val)
{
if (base.IsReadOnly)
{
throw new NotSupportedException("Collection is read-only");
}
this.InvalidateCachedArrays();
ArrayList arrayList = (ArrayList)base.BaseGet(name);
if (arrayList == null)
{
arrayList = new ArrayList();
if (val != null)
{
arrayList.Add(val);
}
base.BaseAdd(name, arrayList);
}
else if (val != null)
{
arrayList.Add(val);
}
}
/// <summary>Invalidates the cached arrays and removes all entries from the <see cref="T:System.Collections.Specialized.NameValueCollection" />.</summary>
/// <exception cref="T:System.NotSupportedException">The collection is read-only.</exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
/// </PermissionSet>
// Token: 0x06000218 RID: 536 RVA: 0x00008314 File Offset: 0x00006514
public virtual void Clear()
{
if (base.IsReadOnly)
{
throw new NotSupportedException("Collection is read-only");
}
this.InvalidateCachedArrays();
base.BaseClear();
}
/// <summary>Copies the entire <see cref="T:System.Collections.Specialized.NameValueCollection" /> to a compatible one-dimensional <see cref="T:System.Array" />, starting at the specified index of the target array.</summary>
/// <param name="dest">The one-dimensional <see cref="T:System.Array" /> that is the destination of the elements copied from <see cref="T:System.Collections.Specialized.NameValueCollection" />. The <see cref="T:System.Array" /> must have zero-based indexing.</param>
/// <param name="index">The zero-based index in <paramref name="dest" /> at which copying begins.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="dest" /> is null.</exception>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="index" /> is less than zero.</exception>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="dest" /> is multidimensional.-or- The number of elements in the source <see cref="T:System.Collections.Specialized.NameValueCollection" /> is greater than the available space from <paramref name="index" /> to the end of the destination <paramref name="dest" />.</exception>
/// <exception cref="T:System.InvalidCastException">The type of the source <see cref="T:System.Collections.Specialized.NameValueCollection" /> cannot be cast automatically to the type of the destination <paramref name="dest" />.</exception>
// Token: 0x06000219 RID: 537 RVA: 0x00008344 File Offset: 0x00006544
public void CopyTo(Array dest, int index)
{
if (dest == null)
{
throw new ArgumentNullException("dest", "Null argument - dest");
}
if (index < 0)
{
throw new ArgumentOutOfRangeException("index", "index is less than 0");
}
if (dest.Rank > 1)
{
throw new ArgumentException("dest", "multidim");
}
if (this.cachedAll == null)
{
this.RefreshCachedAll();
}
try
{
this.cachedAll.CopyTo(dest, index);
}
catch (ArrayTypeMismatchException)
{
throw new InvalidCastException();
}
}
// Token: 0x0600021A RID: 538 RVA: 0x000083E8 File Offset: 0x000065E8
private void RefreshCachedAll()
{
this.cachedAll = null;
int count = this.Count;
this.cachedAll = new string[count];
for (int i = 0; i < count; i++)
{
this.cachedAll[i] = this.Get(i);
}
}
/// <summary>Gets the values at the specified index of the <see cref="T:System.Collections.Specialized.NameValueCollection" /> combined into one comma-separated list.</summary>
/// <returns>A <see cref="T:System.String" /> that contains a comma-separated list of the values at the specified index of the <see cref="T:System.Collections.Specialized.NameValueCollection" />, if found; otherwise, null.</returns>
/// <param name="index">The zero-based index of the entry that contains the values to get from the collection.</param>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="index" /> is outside the valid range of indexes for the collection.</exception>
// Token: 0x0600021B RID: 539 RVA: 0x00008430 File Offset: 0x00006630
public virtual string Get(int index)
{
ArrayList arrayList = (ArrayList)base.BaseGet(index);
return NameValueCollection.AsSingleString(arrayList);
}
/// <summary>Gets the values associated with the specified key from the <see cref="T:System.Collections.Specialized.NameValueCollection" /> combined into one comma-separated list.</summary>
/// <returns>A <see cref="T:System.String" /> that contains a comma-separated list of the values associated with the specified key from the <see cref="T:System.Collections.Specialized.NameValueCollection" />, if found; otherwise, null.</returns>
/// <param name="name">The <see cref="T:System.String" /> key of the entry that contains the values to get. The key can be null.</param>
// Token: 0x0600021C RID: 540 RVA: 0x00008450 File Offset: 0x00006650
public virtual string Get(string name)
{
ArrayList arrayList = (ArrayList)base.BaseGet(name);
return NameValueCollection.AsSingleString(arrayList);
}
// Token: 0x0600021D RID: 541 RVA: 0x00008470 File Offset: 0x00006670
private static string AsSingleString(ArrayList values)
{
if (values == null)
{
return null;
}
int count = values.Count;
switch (count)
{
case 0:
return null;
case 1:
return (string)values[0];
case 2:
return (string)values[0] + ',' + (string)values[1];
default:
{
int num = count;
for (int i = 0; i < count; i++)
{
num += ((string)values[i]).Length;
}
StringBuilder stringBuilder = new StringBuilder((string)values[0], num);
for (int j = 1; j < count; j++)
{
stringBuilder.Append(',');
stringBuilder.Append(values[j]);
}
return stringBuilder.ToString();
}
}
}
/// <summary>Gets the key at the specified index of the <see cref="T:System.Collections.Specialized.NameValueCollection" />.</summary>
/// <returns>A <see cref="T:System.String" /> that contains the key at the specified index of the <see cref="T:System.Collections.Specialized.NameValueCollection" />, if found; otherwise, null.</returns>
/// <param name="index">The zero-based index of the key to get from the collection.</param>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="index" /> is outside the valid range of indexes for the collection. </exception>
// Token: 0x0600021E RID: 542 RVA: 0x00008550 File Offset: 0x00006750
public virtual string GetKey(int index)
{
return base.BaseGetKey(index);
}
/// <summary>Gets the values at the specified index of the <see cref="T:System.Collections.Specialized.NameValueCollection" />.</summary>
/// <returns>A <see cref="T:System.String" /> array that contains the values at the specified index of the <see cref="T:System.Collections.Specialized.NameValueCollection" />, if found; otherwise, null.</returns>
/// <param name="index">The zero-based index of the entry that contains the values to get from the collection.</param>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="index" /> is outside the valid range of indexes for the collection. </exception>
// Token: 0x0600021F RID: 543 RVA: 0x0000855C File Offset: 0x0000675C
public virtual string[] GetValues(int index)
{
ArrayList arrayList = (ArrayList)base.BaseGet(index);
return NameValueCollection.AsStringArray(arrayList);
}
/// <summary>Gets the values associated with the specified key from the <see cref="T:System.Collections.Specialized.NameValueCollection" />.</summary>
/// <returns>A <see cref="T:System.String" /> array that contains the values associated with the specified key from the <see cref="T:System.Collections.Specialized.NameValueCollection" />, if found; otherwise, null.</returns>
/// <param name="name">The <see cref="T:System.String" /> key of the entry that contains the values to get. The key can be null.</param>
// Token: 0x06000220 RID: 544 RVA: 0x0000857C File Offset: 0x0000677C
public virtual string[] GetValues(string name)
{
ArrayList arrayList = (ArrayList)base.BaseGet(name);
return NameValueCollection.AsStringArray(arrayList);
}
// Token: 0x06000221 RID: 545 RVA: 0x0000859C File Offset: 0x0000679C
private static string[] AsStringArray(ArrayList values)
{
if (values == null)
{
return null;
}
int count = values.Count;
if (count == 0)
{
return null;
}
string[] array = new string[count];
values.CopyTo(array);
return array;
}
/// <summary>Gets a value indicating whether the <see cref="T:System.Collections.Specialized.NameValueCollection" /> contains keys that are not null.</summary>
/// <returns>true if the <see cref="T:System.Collections.Specialized.NameValueCollection" /> contains keys that are not null; otherwise, false.</returns>
// Token: 0x06000222 RID: 546 RVA: 0x000085D0 File Offset: 0x000067D0
public bool HasKeys()
{
return base.BaseHasKeys();
}
/// <summary>Removes the entries with the specified key from the <see cref="T:System.Collections.Specialized.NameObjectCollectionBase" /> instance.</summary>
/// <param name="name">The <see cref="T:System.String" /> key of the entry to remove. The key can be null.</param>
/// <exception cref="T:System.NotSupportedException">The collection is read-only.</exception>
// Token: 0x06000223 RID: 547 RVA: 0x000085D8 File Offset: 0x000067D8
public virtual void Remove(string name)
{
if (base.IsReadOnly)
{
throw new NotSupportedException("Collection is read-only");
}
this.InvalidateCachedArrays();
base.BaseRemove(name);
}
/// <summary>Sets the value of an entry in the <see cref="T:System.Collections.Specialized.NameValueCollection" />.</summary>
/// <param name="name">The <see cref="T:System.String" /> key of the entry to add the new value to. The key can be null.</param>
/// <param name="value">The <see cref="T:System.Object" /> that represents the new value to add to the specified entry. The value can be null.</param>
/// <exception cref="T:System.NotSupportedException">The collection is read-only.</exception>
// Token: 0x06000224 RID: 548 RVA: 0x00008600 File Offset: 0x00006800
public virtual void Set(string name, string value)
{
if (base.IsReadOnly)
{
throw new NotSupportedException("Collection is read-only");
}
this.InvalidateCachedArrays();
ArrayList arrayList = new ArrayList();
if (value != null)
{
arrayList.Add(value);
base.BaseSet(name, arrayList);
}
else
{
base.BaseSet(name, null);
}
}
/// <summary>Resets the cached arrays of the collection to null.</summary>
// Token: 0x06000225 RID: 549 RVA: 0x00008654 File Offset: 0x00006854
protected void InvalidateCachedArrays()
{
this.cachedAllKeys = null;
this.cachedAll = null;
}
// Token: 0x040000A4 RID: 164
private string[] cachedAllKeys;
// Token: 0x040000A5 RID: 165
private string[] cachedAll;
}
}