Beispiel #1
0
        /// <summary>
        /// 从子元素集合中移除指定标志的第一个匹配项。
        /// </summary>
        /// <param name="token">指定标志。</param>
        /// <returns>操作是否成功</returns>
        /// <exception cref="ArgumentNullException">
        /// 参数<paramref name="token"/>为<see langword="null"/>。
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// 参数<paramref name="token"/>指定的标志不存在于<see cref="Children"/>中。
        /// </exception>
        public bool Remove(NDToken token)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            if (!this.Children.Contains(token))
            {
                throw new InvalidOperationException("子元素集合中不存在对象。");
            }

            return(this.Children.Remove(token));
        }
Beispiel #2
0
        /// <summary>
        /// 向子元素集合中添加一个标志。
        /// </summary>
        /// <param name="token"></param>
        /// <exception cref="ArgumentNullException">
        /// 参数<paramref name="token"/>为<see langword="null"/>。
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// 参数<paramref name="token"/>指定的标志的<see cref="Parent"/>父元素已经赋值了另一个<see cref="NDToken"/>对象,且其不等于此<see cref="NDToken"/>对象。
        /// </exception>
        public void Add(NDToken token)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            if (token.Parent != null && token.Parent != this)
            {
                throw new InvalidOperationException("标志已经有父元素,无法覆盖。");
            }

            token.Parent = this;
            this.Children.Add(token);
        }