예제 #1
0
파일: JProperty.cs 프로젝트: cs130-w21/13
 internal override void SetItem(int index, JToken item) {
   if (index != 0)
     throw new ArgumentOutOfRangeException();
   if (JContainer.IsTokenUnchanged(this.Value, item))
     return;
   ((JObject) this.Parent)?.InternalPropertyChanging(this);
   base.SetItem(0, item);
   ((JObject) this.Parent)?.InternalPropertyChanged(this);
 }
예제 #2
0
파일: JContainer.cs 프로젝트: cs130-w21/13
        internal virtual void SetItem(int index, JToken item)
        {
            IList <JToken> childrenTokens = this.ChildrenTokens;

            if (index < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(index), "Index is less than 0.");
            }
            if (index >= childrenTokens.Count)
            {
                throw new ArgumentOutOfRangeException(nameof(index), "Index is equal to or greater than Count.");
            }
            JToken jtoken1 = childrenTokens[index];

            if (JContainer.IsTokenUnchanged(jtoken1, item))
            {
                return;
            }
            this.CheckReentrancy();
            item = this.EnsureParentToken(item, false);
            this.ValidateToken(item, jtoken1);
            JToken jtoken2 = index == 0 ? (JToken)null : childrenTokens[index - 1];
            JToken jtoken3 = index == childrenTokens.Count - 1 ? (JToken)null : childrenTokens[index + 1];

            item.Parent   = this;
            item.Previous = jtoken2;
            if (jtoken2 != null)
            {
                jtoken2.Next = item;
            }
            item.Next = jtoken3;
            if (jtoken3 != null)
            {
                jtoken3.Previous = item;
            }
            childrenTokens[index] = item;
            jtoken1.Parent        = (JContainer)null;
            jtoken1.Previous      = (JToken)null;
            jtoken1.Next          = (JToken)null;
            if (this._listChanged == null)
            {
                return;
            }
            this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, index));
        }