private bool m_readonly;
SerializationInfo infoCopy;
private KeysCollection keyscoll;
-#if NET_2_0
private IEqualityComparer equality_comparer;
internal IEqualityComparer EqualityComparer {
get { return equality_comparer; }
}
-#endif
+
internal IComparer Comparer {
get {return m_comparer;}
}
}
public bool MoveNext()
{
- return ((++m_position)<m_collection.Count)?true:false;
+ return ((++m_position) < m_collection.Count);
}
public void Reset()
{
}
// ICollection methods -----------------------------------
- void ICollection.CopyTo(Array arr, int index)
+ void ICollection.CopyTo (Array array, int arrayIndex)
{
- if (arr==null)
- throw new ArgumentNullException("array can't be null");
- IEnumerator en = this.GetEnumerator();
- int i = index;
- while (en.MoveNext())
- {
- arr.SetValue(en.Current,i);
- i++;
- }
+ ArrayList items = m_collection.m_ItemsArray;
+ if (null == array)
+ throw new ArgumentNullException ("array");
+
+ if (arrayIndex < 0)
+ throw new ArgumentOutOfRangeException ("arrayIndex");
+
+ if ((array.Length > 0) && (arrayIndex >= array.Length))
+ throw new ArgumentException ("arrayIndex is equal to or greater than array.Length");
+
+ if (arrayIndex + items.Count > array.Length)
+ throw new ArgumentException ("Not enough room from arrayIndex to end of array for this KeysCollection");
+
+ if (array != null && array.Rank > 1)
+ throw new ArgumentException ("array is multidimensional");
+
+ object[] objArray = (object[])array;
+ for (int i = 0; i < items.Count; i++, arrayIndex++)
+ objArray [arrayIndex] = ((_Item)items [i]).key;
}
bool ICollection.IsSynchronized
protected NameObjectCollectionBase ()
{
m_readonly = false;
-#if NET_1_0
- m_hashprovider = CaseInsensitiveHashCodeProvider.Default;
- m_comparer = CaseInsensitiveComparer.Default;
-#else
m_hashprovider = CaseInsensitiveHashCodeProvider.DefaultInvariant;
m_comparer = CaseInsensitiveComparer.DefaultInvariant;
-#endif
m_defCapacity = 0;
Init();
}
protected NameObjectCollectionBase( int capacity )
{
m_readonly = false;
-#if NET_1_0
- m_hashprovider = CaseInsensitiveHashCodeProvider.Default;
- m_comparer = CaseInsensitiveComparer.Default;
-#else
m_hashprovider = CaseInsensitiveHashCodeProvider.DefaultInvariant;
m_comparer = CaseInsensitiveComparer.DefaultInvariant;
-#endif
m_defCapacity = capacity;
Init();
- }
+ }
-#if NET_2_0
- protected NameObjectCollectionBase (IEqualityComparer equalityComparer)
+ internal NameObjectCollectionBase (IEqualityComparer equalityComparer, IComparer comparer, IHashCodeProvider hcp)
{
- m_readonly = false;
equality_comparer = equalityComparer;
+ m_comparer = comparer;
+ m_hashprovider = hcp;
+ m_readonly = false;
m_defCapacity = 0;
- Init();
+ Init ();
}
+ protected NameObjectCollectionBase (IEqualityComparer equalityComparer) : this( (equalityComparer == null ? StringComparer.InvariantCultureIgnoreCase : equalityComparer), null, null)
+ {
+ }
+
[Obsolete ("Use NameObjectCollectionBase(IEqualityComparer)")]
-#endif
protected NameObjectCollectionBase( IHashCodeProvider hashProvider, IComparer comparer )
- {
- m_readonly = false;
-
- m_hashprovider = hashProvider;
+ {
m_comparer = comparer;
+ m_hashprovider = hashProvider;
+ m_readonly = false;
m_defCapacity = 0;
- Init();
+ Init ();
}
protected NameObjectCollectionBase (SerializationInfo info, StreamingContext context)
infoCopy = info;
}
-#if NET_2_0
protected NameObjectCollectionBase (int capacity, IEqualityComparer equalityComparer)
{
m_readonly = false;
- equality_comparer = equalityComparer;
+ equality_comparer = (equalityComparer == null ? StringComparer.InvariantCultureIgnoreCase : equalityComparer);
m_defCapacity = capacity;
Init();
}
[Obsolete ("Use NameObjectCollectionBase(int,IEqualityComparer)")]
-#endif
protected NameObjectCollectionBase( int capacity, IHashCodeProvider hashProvider, IComparer comparer )
{
m_readonly = false;
private void Init ()
{
-#if NET_2_0
+ if (m_ItemsContainer != null) {
+ m_ItemsContainer.Clear ();
+ m_ItemsContainer = null;
+ }
+
+ if (m_ItemsArray != null) {
+ m_ItemsArray.Clear ();
+ m_ItemsArray = null;
+ }
if (equality_comparer != null)
m_ItemsContainer = new Hashtable (m_defCapacity, equality_comparer);
else
m_ItemsContainer = new Hashtable (m_defCapacity, m_hashprovider, m_comparer);
-#else
- m_ItemsContainer = new Hashtable (m_defCapacity, m_hashprovider, m_comparer);
-#endif
m_ItemsArray = new ArrayList();
m_NullKeyItem = null;
}
/// <remark>This enumerator returns the keys of the collection as strings.</remark>
/// </summary>
/// <returns></returns>
- public
-#if NET_2_0
- virtual
-#endif
- IEnumerator GetEnumerator()
+ public virtual IEnumerator GetEnumerator()
{
return new _KeysEnumerator(this);
}
i++;
}
-#if NET_2_0
if (equality_comparer != null) {
info.AddValue ("KeyComparer", equality_comparer, typeof (IEqualityComparer));
info.AddValue ("Version", 4, typeof (int));
info.AddValue ("Comparer", m_comparer, typeof (IComparer));
info.AddValue ("Version", 2, typeof (int));
}
-#else
- info.AddValue ("HashProvider", m_hashprovider, typeof (IHashCodeProvider));
- info.AddValue ("Comparer", m_comparer, typeof (IComparer));
-#endif
info.AddValue("ReadOnly", m_readonly);
info.AddValue("Count", count);
info.AddValue("Keys", keys, typeof(string[]));
void ICollection.CopyTo (Array array, int index)
{
- (Keys as ICollection).CopyTo (array, index);
+ ((ICollection)Keys).CopyTo (array, index);
}
// IDeserializationCallback
infoCopy = null;
m_hashprovider = (IHashCodeProvider) info.GetValue ("HashProvider",
typeof (IHashCodeProvider));
-#if NET_2_0
if (m_hashprovider == null) {
equality_comparer = (IEqualityComparer) info.GetValue ("KeyComparer", typeof (IEqualityComparer));
} else {
if (m_comparer == null)
throw new SerializationException ("The comparer is null");
}
-#else
- if (m_hashprovider == null)
- throw new SerializationException ("The hash provider is null");
-
- m_comparer = (IComparer) info.GetValue ("Comparer", typeof (IComparer));
- if (m_comparer == null)
- throw new SerializationException ("The comparer is null");
-#endif
m_readonly = info.GetBoolean ("ReadOnly");
string [] keys = (string []) info.GetValue ("Keys", typeof (string []));
if (keys == null)
/// It's ok only then the key is uniquely assosiated with the value
/// To fix it a comparsion of objects stored under the same key in the hashtable and in the arraylist should be added
/// </LAME>>
- [MonoTODO]
protected void BaseRemoveAt( int index )
{
if (this.IsReadOnly)
internal bool Equals (string s1, string s2)
{
-#if NET_2_0
if (m_comparer != null)
return (m_comparer.Compare (s1, s2) == 0);
else
return equality_comparer.Equals (s1, s2);
-#else
- return (m_comparer.Compare (s1, s2) == 0);
-#endif
}
}
}