/// <summary>
 ///		Returns the zero-based index of the first occurrence of a <see cref="FormattingInstruction"/>
 ///		in the <c>FormattingInstructionCollection</c>.
 /// </summary>
 /// <param name="item">The <see cref="FormattingInstruction"/> to locate in the <c>FormattingInstructionCollection</c>.</param>
 /// <returns>
 ///		The zero-based index of the first occurrence of <paramref name="item"/>
 ///		in the entire <c>FormattingInstructionCollection</c>, if found; otherwise, -1.
 ///	</returns>
 public virtual int IndexOf(FormattingInstruction 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="FormattingInstruction"/> is in the <c>FormattingInstructionCollection</c>.
 /// </summary>
 /// <param name="item">The <see cref="FormattingInstruction"/> to check for.</param>
 /// <returns><c>true</c> if <paramref name="item"/> is found in the <c>FormattingInstructionCollection</c>; otherwise, <c>false</c>.</returns>
 public virtual bool Contains(FormattingInstruction item)
 {
     for (int i = 0; i != m_count; ++i)
     {
         if (m_array[i].Equals(item))
         {
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        ///		Adds a <see cref="FormattingInstruction"/> to the end of the <c>FormattingInstructionCollection</c>.
        /// </summary>
        /// <param name="item">The <see cref="FormattingInstruction"/> to be added to the end of the <c>FormattingInstructionCollection</c>.</param>
        /// <returns>The index at which the value has been added.</returns>
        public virtual int Add(FormattingInstruction item)
        {
            if (m_count == m_array.Length)
            {
                EnsureCapacity(m_count + 1);
            }

            m_array[m_count] = item;
            m_version++;

            return(m_count++);
        }
            public override void Remove(FormattingInstruction x)
            {
                rwLock.AcquireWriterLock(timeout);

                try
                {
                    collection.Remove(x);
                }
                finally
                {
                    rwLock.ReleaseWriterLock();
                }
            }
            public override void Insert(int pos, FormattingInstruction x)
            {
                rwLock.AcquireWriterLock(timeout);

                try
                {
                    collection.Insert(pos, x);
                }
                finally
                {
                    rwLock.ReleaseWriterLock();
                }
            }
        /// <summary>
        ///		Removes the first occurrence of a specific <see cref="FormattingInstruction"/> from the <c>FormattingInstructionCollection</c>.
        /// </summary>
        /// <param name="item">The <see cref="FormattingInstruction"/> to remove from the <c>FormattingInstructionCollection</c>.</param>
        /// <exception cref="ArgumentException">
        ///		The specified <see cref="FormattingInstruction"/> was not found in the <c>FormattingInstructionCollection</c>.
        /// </exception>
        public virtual void Remove(FormattingInstruction item)
        {
            int i = IndexOf(item);

            if (i < 0)
            {
                throw new ArgumentException(
                          "Cannot remove the specified item because it was not found in the specified Collection.");
            }

            ++m_version;
            RemoveAt(i);
        }
            public override int IndexOf(FormattingInstruction x)
            {
                int result = 0;

                rwLock.AcquireReaderLock(timeout);

                try
                {
                    result = collection.IndexOf(x);
                }
                finally
                {
                    rwLock.ReleaseReaderLock();
                }

                return(result);
            }
            public override bool Contains(FormattingInstruction x)
            {
                bool result = false;

                rwLock.AcquireReaderLock(timeout);

                try
                {
                    result = collection.Contains(x);
                }
                finally
                {
                    rwLock.ReleaseReaderLock();
                }

                return(result);
            }
            public override int Add(FormattingInstruction x)
            {
                int result = 0;

                rwLock.AcquireWriterLock(timeout);

                try
                {
                    result = collection.Add(x);
                }
                finally
                {
                    rwLock.ReleaseWriterLock();
                }

                return(result);
            }
        /// <summary>
        ///		Removes the element at the specified index of the <c>FormattingInstructionCollection</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="FormattingInstructionCollection.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.
            FormattingInstruction[] temp = new FormattingInstruction[1];
            Array.Copy(temp, 0, m_array, m_count, 1);
            m_version++;
        }
        /// <summary>
        ///		Inserts an element into the <c>FormattingInstructionCollection</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="FormattingInstruction"/> 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="FormattingInstructionCollection.Count"/>.</para>
        /// </exception>
        public virtual void Insert(int index, FormattingInstruction 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++;
        }
Example #12
0
 private void SetFormat(FormattingInstruction instruction)
 {
     SelectionStart  = instruction.Start;
     SelectionLength = instruction.Length;
     SetSelectionFormat(instruction.Format);
 }
 public override void Remove(FormattingInstruction x)
 {
     throw new NotSupportedException("This is a Read Only Collection and can not be modified");
 }
 public override int IndexOf(FormattingInstruction x)
 {
     return(m_collection.IndexOf(x));
 }
 public override bool Contains(FormattingInstruction x)
 {
     return(m_collection.Contains(x));
 }