Exemple #1
0
        public void Insert(int index, Block item)
        {
            if (item is null)
            {
                ThrowHelper.ArgumentNullException_item();
            }

            if (item.Parent != null)
            {
                ThrowHelper.ArgumentException("Cannot add this block as it as already attached to another container (block.Parent != null)");
            }
            if ((uint)index > (uint)Count)
            {
                ThrowHelper.ArgumentOutOfRangeException_index();
            }
            if (Count == _children.Length)
            {
                Grow();
            }
            if (index < Count)
            {
                Array.Copy(_children, index, _children, index + 1, Count - index);
            }
            _children[index] = new BlockWrapper(item);
            Count++;
            item.Parent = this;
        }
Exemple #2
0
        public void Insert(int index, Block item)
        {
            if (item == null)
            {
                ThrowHelper.ArgumentNullException_item();
            }

            if (item.Parent != null)
            {
                ThrowHelper.ArgumentException("Cannot add this block as it as already attached to another container (block.Parent != null)");
            }
            if ((uint)index > (uint)Count)
            {
                ThrowHelper.ArgumentOutOfRangeException_index();
            }
            if (Count == children.Length)
            {
                EnsureCapacity(Count + 1);
            }
            if (index < Count)
            {
                Array.Copy(children, index, children, index + 1, Count - index);
            }
            children[index] = item;
            Count++;
            item.Parent = this;
        }
Exemple #3
0
        public int IndexOf(Block item)
        {
            if (item == null)
            {
                ThrowHelper.ArgumentNullException_item();
            }

            for (int i = 0; i < Count; i++)
            {
                if (children[i] == item)
                {
                    return(i);
                }
            }
            return(-1);
        }
Exemple #4
0
        public bool Contains(Block item)
        {
            if (item == null)
            {
                ThrowHelper.ArgumentNullException_item();
            }

            for (int i = 0; i < Count; i++)
            {
                if (children[i] == item)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #5
0
        public bool Remove(Block item)
        {
            if (item == null)
            {
                ThrowHelper.ArgumentNullException_item();
            }

            for (int i = Count - 1; i >= 0; i--)
            {
                if (children[i] == item)
                {
                    RemoveAt(i);
                    return(true);
                }
            }
            return(false);
        }
Exemple #6
0
        public int IndexOf(Block item)
        {
            if (item is null)
            {
                ThrowHelper.ArgumentNullException_item();
            }

            BlockWrapper[] children = _children;
            for (int i = 0; i < Count && i < children.Length; i++)
            {
                if (ReferenceEquals(children[i].Block, item))
                {
                    return(i);
                }
            }
            return(-1);
        }
Exemple #7
0
        public void Add(Block item)
        {
            if (item == null)
            {
                ThrowHelper.ArgumentNullException_item();
            }

            if (item.Parent != null)
            {
                ThrowHelper.ArgumentException("Cannot add this block as it as already attached to another container (block.Parent != null)");
            }

            if (Count == children.Length)
            {
                EnsureCapacity(Count + 1);
            }
            children[Count++] = item;
            item.Parent       = this;

            UpdateSpanEnd(item.Span.End);
        }
Exemple #8
0
        public Block this[int index]
        {
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            get
            {
                var array = _children;
                if ((uint)index >= (uint)array.Length || index >= Count)
                {
                    ThrowHelper.ThrowIndexOutOfRangeException();
                    return(null);
                }
                return(array[index].Block);
            }
            set
            {
                if ((uint)index >= (uint)Count)
                {
                    ThrowHelper.ThrowIndexOutOfRangeException();
                }

                if (value is null)
                {
                    ThrowHelper.ArgumentNullException_item();
                }

                if (value.Parent != null)
                {
                    ThrowHelper.ArgumentException("Cannot add this block as it as already attached to another container (block.Parent != null)");
                }

                var existingChild = _children[index].Block;
                if (existingChild != null)
                {
                    existingChild.Parent = null;
                }

                value.Parent     = this;
                _children[index] = new BlockWrapper(value);
            }
        }
Exemple #9
0
        public Block this[int index]
        {
            get
            {
                var array = children;
                if ((uint)index >= (uint)array.Length || index >= Count)
                {
                    ThrowHelper.ThrowIndexOutOfRangeException();
                    return(null);
                }
                return(array[index]);
            }
            set
            {
                if ((uint)index >= (uint)Count)
                {
                    ThrowHelper.ThrowIndexOutOfRangeException();
                }

                if (value == null)
                {
                    ThrowHelper.ArgumentNullException_item();
                }

                if (value.Parent != null)
                {
                    ThrowHelper.ArgumentException("Cannot add this block as it as already attached to another container (block.Parent != null)");
                }

                var existingChild = children[index];
                if (existingChild != null)
                {
                    existingChild.Parent = null;
                }

                value.Parent    = this;
                children[index] = value;
            }
        }
Exemple #10
0
        public void Add(Block item)
        {
            if (item is null)
            {
                ThrowHelper.ArgumentNullException_item();
            }

            if (item.Parent != null)
            {
                ThrowHelper.ArgumentException("Cannot add this block as it as already attached to another container (block.Parent != null)");
            }

            if (Count == _children.Length)
            {
                Grow();
            }
            _children[Count] = new BlockWrapper(item);
            Count++;
            item.Parent = this;

            UpdateSpanEnd(item.Span.End);
        }