/// <summary> /// Returns the zero-based index of the first occurrence of a <see cref="BaseValidator"/> /// in the <c>ValidatorCollection</c>. /// </summary> /// <param name="item">The <see cref="BaseValidator"/> to locate in the <c>ValidatorCollection</c>.</param> /// <returns> /// The zero-based index of the first occurrence of <paramref name="item"/> /// in the entire <c>ValidatorCollection</c>, if found; otherwise, -1. /// </returns> public virtual int IndexOf(BaseValidator item) { for (int i = 0; i != m_count; ++i) { if (m_array[i].Equals(item)) { return(i); } } return(-1); }
/// <summary> /// Determines whether a given <see cref="BaseValidator"/> is in the <c>ValidatorCollection</c>. /// </summary> /// <param name="item">The <see cref="BaseValidator"/> to check for.</param> /// <returns><c>true</c> if <paramref name="item"/> is found in the <c>ValidatorCollection</c>; otherwise, <c>false</c>.</returns> public virtual bool Contains(BaseValidator item) { for (int i = 0; i != m_count; ++i) { if (m_array[i].Equals(item)) { return(true); } } return(false); }
/// <summary> /// Removes the first occurrence of a specific <see cref="BaseValidator"/> from the <c>ValidatorCollection</c>. /// </summary> /// <param name="item">The <see cref="BaseValidator"/> to remove from the <c>ValidatorCollection</c>.</param> /// <exception cref="ArgumentException"> /// The specified <see cref="BaseValidator"/> was not found in the <c>ValidatorCollection</c>. /// </exception> public virtual void Remove(BaseValidator item) { int i = IndexOf(item); if (i < 0) { throw new System.ArgumentException("Cannot remove the specified item because it was not found in the specified Collection."); } ++m_version; RemoveAt(i); }
/// <summary> /// Adds a <see cref="BaseValidator"/> to the end of the <c>ValidatorCollection</c>. /// </summary> /// <param name="item">The <see cref="BaseValidator"/> to be added to the end of the <c>ValidatorCollection</c>.</param> /// <returns>The index at which the value has been added.</returns> public virtual int Add(BaseValidator item) { if (m_count == m_array.Length) { EnsureCapacity(m_count + 1); } m_array[m_count] = item; m_version++; return(m_count++); }
public static void DeRegister(BaseValidator validator, Form hostingForm) { // Remove this validator from the list of registered validators ValidatorCollection validators = (ValidatorCollection)_validators[hostingForm]; validators.Remove(validator); // Remove form bucket if all validators on the form are de-registered if (validators.Count == 0) { _validators.Remove(hostingForm); } }
// TODO: //private static Dictionary<Form, ValidatorCollection> validators = new Dictionary<Form, ValidatorCollection>(); public static void Register(BaseValidator validator, Form hostingForm) { // Create form bucket if it doesn't exist if (_validators[hostingForm] == null) { _validators[hostingForm] = new ValidatorCollection(); } // Add this validator to the list of registered validators ValidatorCollection validators = (ValidatorCollection)_validators[hostingForm]; validators.Add(validator); }
/// <summary> /// Removes the element at the specified index of the <c>ValidatorCollection</c>. /// </summary> /// <param name="index">The zero-based index of the element to remove.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero</para> /// <para>-or-</para> /// <para><paramref name="index"/> is equal to or greater than <see cref="ValidatorCollection.Count"/>.</para> /// </exception> public virtual void RemoveAt(int index) { ValidateIndex(index); // throws m_count--; if (index < m_count) { Array.Copy(m_array, index + 1, m_array, index, m_count - index); } // We can't set the deleted entry equal to null, because it might be a value type. // Instead, we'll create an empty single-element array of the right type and copy it // over the entry we want to erase. BaseValidator[] temp = new BaseValidator[1]; Array.Copy(temp, 0, m_array, m_count, 1); m_version++; }
/// <summary> /// Inserts an element into the <c>ValidatorCollection</c> at the specified index. /// </summary> /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param> /// <param name="item">The <see cref="BaseValidator"/> to insert.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero</para> /// <para>-or-</para> /// <para><paramref name="index"/> is equal to or greater than <see cref="ValidatorCollection.Count"/>.</para> /// </exception> public virtual void Insert(int index, BaseValidator item) { ValidateIndex(index, true); // throws if (m_count == m_array.Length) { EnsureCapacity(m_count + 1); } if (index < m_count) { Array.Copy(m_array, index, m_array, index + 1, m_count - index); } m_array[index] = item; m_count++; m_version++; }
public override void Remove(BaseValidator x) { throw new NotSupportedException("This is a Read Only Collection and can not be modified"); }
public override int IndexOf(BaseValidator x) { return(m_collection.IndexOf(x)); }
public override bool Contains(BaseValidator x) { return(m_collection.Contains(x)); }
public override void Remove(BaseValidator x) { lock (this.m_root) m_collection.Remove(x); }
public override void Insert(int pos, BaseValidator x) { lock (this.m_root) m_collection.Insert(pos, x); }
public override int IndexOf(BaseValidator x) { lock (this.m_root) return(m_collection.IndexOf(x)); }
public override bool Contains(BaseValidator x) { lock (this.m_root) return(m_collection.Contains(x)); }
public override int Add(BaseValidator x) { lock (this.m_root) return(m_collection.Add(x)); }