Example #1
0
 protected void Add(int index, IonValueLite item)
 {
     if (index < 0 || index > ChildCount)
     {
         throw new IndexOutOfRangeException();
     }
     CheckLocked();
     ValidateNewChild(item);
     AddChild(index, item);
     PatchElement(index + 1);
 }
Example #2
0
        private static void ValidateNewChild(IonValueLite child)
        {
            if (child.Container != null)
            {
                throw new ContainedValueException();
            }
            if (child.ReadOnly)
            {
                throw new ReadOnlyException();
            }

            if (child is IIonDatagram)
            {
                throw new InvalidOperationException("IonDatagram can not be inserted into another IonContainer.");
            }
        }
Example #3
0
        protected int AddChild(int index, IonValueLite child)
        {
            IsNullValue(false);
            child.SetContext(this);
            if (Children == null || ChildCount >= Children.Length)
            {
                var oldLength = Children?.Length ?? 0;
                var newLength = NextSize(oldLength, true);
                Array.Resize(ref Children, newLength);
            }

            if (index < ChildCount)
            {
                Array.Copy(Children, index, Children, index + 1, ChildCount - index);
            }

            ChildCount++;
            Children[index] = child;

            child.SetElementId(index);
            return(index);
        }