Ejemplo n.º 1
0
 /// <summary>
 /// Raises <see cref="CollectionModified" /> and <see cref="RangeAdded" /> events
 /// </summary>
 /// <param name="e">An <see cref="EasyTabs.EventList.ListRangeEventArgs" /> that contains the event data</param>
 protected virtual void OnRangeAdded(ListRangeEventArgs e)
 {
     if (IgnoreEvents)
     {
         return;
     }
     RangeAdded?.Invoke(this, e);
     OnCollectionModified(new ListModificationEventArgs(ListModification.RangeAdded, e.StartIndex, e.Count));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Add a range to the collection of ranges this rule applies to.
        /// If the specified range does not belong to the worksheet of the data validation
        /// rule it is transferred to the target worksheet.
        /// </summary>
        /// <param name="range">A range to add.</param>
        public void AddRange(IXLRange range)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            if (range.Worksheet != Worksheet)
            {
                range = Worksheet.Range(((XLRangeAddress)range.RangeAddress).WithoutWorksheet());
            }

            _ranges.Add(range);

            RangeAdded?.Invoke(this, new RangeEventArgs(range));
        }
Ejemplo n.º 3
0
        /// <summary>Inserts the elements of a collection into the list at the specified index.</summary>
        /// <param name="index">The zero-based index at which the new elements should be inserted.</param>
        /// <param name="elements">
        ///     The collection whose elements should be inserted into the list.
        ///     The collection itself cannot be null, but it can contain elements that are null,
        ///     if type <typeparamref name="T" /> is a reference type.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">index is less than 0 -or- index is greater than Count.</exception>
        public void InsertRange(int index, [NotNull] IEnumerable <T> elements)
        {
            Check.NotNull(elements)
            .InRange(index, 0, Count, "index is less than 0 -or- index is greater than Count.",
                     nameof(index));

            // First call the pre-event if needed, enumerating sequence in process:
            var             success       = true;
            IEnumerable <T> fixedElements = null;
            var             beforeRangeAdditionHandler = Volatile.Read(ref BeforeRangeAddition);

            if (EventsEnabled && (beforeRangeAdditionHandler != null))
            {
                // ReSharper disable PossibleMultipleEnumeration
                fixedElements = elements as ICollection <T> ?? elements.ToArray();
                success       = beforeRangeAdditionHandler(this, index, (ICollection <T>)fixedElements);
            }

            if (success)
            {
                // Enumerated sequence will be null if pre-event was not called, since no enumeration was done.
                if (fixedElements == null)
                {
                    fixedElements = elements;
                }

                // ReSharper enable PossibleMultipleEnumeration
                var countBefore = Count;
                _list.InsertRange(index, fixedElements);

                var addedTotal = Count - countBefore;
                if (EventsEnabled && (addedTotal > 0))
                {
                    RangeAdded.Call(this, index, addedTotal);
                }
            }
        }