/// <summary>
 /// 在 <see cref="ConfigurationElementCollection{TElement}"/> 中的指定索引处插入项。
 /// </summary>
 /// <param name="index">应插入 <paramref name="value"/> 的位置的零始索引。</param>
 /// <param name="value">要插入 <see cref="ConfigurationElementCollection{TElement}"/> 中的对象。</param>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/>
 /// 不是 <see cref="ConfigurationElementCollection{TElement}"/> 中的有效索引。</exception>
 void IList.Insert(int index, object value)
 {
     if (!(value is TElement))
     {
         throw CommonExceptions.ArgumentWrongType("value", value, typeof(TElement));
     }
     Contract.EndContractBlock();
     this.BaseAdd(index, (TElement)value);
 }
        /// <summary>
        /// 向 <see cref="ConfigurationElementCollection{TElement}"/> 中添加项。
        /// </summary>
        /// <param name="value">要添加到 <see cref="ConfigurationElementCollection{TElement}"/> 的对象。</param>
        /// <returns>新元素所插入到的位置,或为 <c>-1</c> 以指示未将该项插入到集合中。</returns>
        int IList.Add(object value)
        {
            int      idx  = this.Count;
            TElement item = value as TElement;

            if (item == null)
            {
                throw CommonExceptions.ArgumentWrongType("value", value, typeof(TElement));
            }
            this.BaseAdd(idx, item);
            return(idx);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 向 <see cref="ConfigurationElementCollection{TElement}"/> 中添加项。
        /// </summary>
        /// <param name="value">要添加到 <see cref="ConfigurationElementCollection{TElement}"/> 的对象。</param>
        /// <returns>新元素所插入到的位置,或为 <c>-1</c> 以指示未将该项插入到集合中。</returns>
        int IList.Add(object value)
        {
            var idx  = Count;
            var item = value as TElement;

            if (item == null)
            {
                throw CommonExceptions.ArgumentWrongType(nameof(value), value, typeof(TElement));
            }
            BaseAdd(idx, item);
            return(idx);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 将指定对象添加到 <see cref="ListBase{T}"/> 的末尾。
 /// </summary>
 /// <param name="value">要添加到 <see cref="ListBase{T}"/> 的末尾的对象。</param>
 /// <returns>新元素所插入到的位置,或为 <c>-1</c> 以指示未将该项插入到集合中。</returns>
 /// <exception cref="ArgumentException"><paramref name="value"/> 不能赋值给
 /// <typeparamref name="T"/> 类型。</exception>
 int IList.Add(object value)
 {
     Contract.Ensures(Contract.Result <int>() >= -1 &&
                      Contract.Result <int>() <= Contract.OldValue(Count));
     try
     {
         int idx = this.Count;
         this.InsertItem(idx, (T)value);
         return(idx);
     }
     catch (InvalidCastException)
     {
         throw CommonExceptions.ArgumentWrongType("value", value, typeof(T));
     }
 }
 /// <summary>
 /// 获取或设置指定索引处的元素。
 /// </summary>
 /// <param name="index">要获得或设置的元素从零开始的索引。</param>
 /// <value>指定索引处的元素。</value>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/>
 /// 不是 <see cref="ConfigurationElementCollection{TElement}"/> 中的有效索引。</exception>
 object IList.this[int index]
 {
     get { return(BaseGet(index)); }
     set
     {
         if (!(value is TElement))
         {
             throw CommonExceptions.ArgumentWrongType("value", value, typeof(TElement));
         }
         Contract.EndContractBlock();
         // 先添加后删除,如果添加失败,不会导致配置元素被删除。
         this.BaseAdd(index, (TElement)value);
         BaseRemoveAt(index + 1);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 在 <see cref="ValueConfigurationCollection"/> 中的指定索引处插入项。
        /// </summary>
        /// <param name="index">应插入 <paramref name="value"/> 的位置的零始索引。</param>
        /// <param name="value">要插入 <see cref="ValueConfigurationCollection"/> 中的对象。</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/>
        /// 不是 <see cref="ValueConfigurationCollection"/> 中的有效索引。</exception>
        void IList.Insert(int index, object value)
        {
            var str = value as string;

            if (str != null)
            {
                Insert(index, str);
                return;
            }
            var element = value as ValueConfigurationElement;

            if (element == null)
            {
                throw CommonExceptions.ArgumentWrongType(nameof(value));
            }
            BaseAdd(index, element);
        }
        /// <summary>
        /// 在 <see cref="ValueConfigurationCollection"/> 中的指定索引处插入项。
        /// </summary>
        /// <param name="index">应插入 <paramref name="value"/> 的位置的零始索引。</param>
        /// <param name="value">要插入 <see cref="ValueConfigurationCollection"/> 中的对象。</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/>
        /// 不是 <see cref="ValueConfigurationCollection"/> 中的有效索引。</exception>
        void IList.Insert(int index, object value)
        {
            string str = value as string;

            if (str != null)
            {
                this.Insert(index, str);
                return;
            }
            ValueConfigurationElement element = value as ValueConfigurationElement;

            if (element == null)
            {
                throw CommonExceptions.ArgumentWrongType("value");
            }
            this.BaseAdd(index, element);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 向 <see cref="ValueConfigurationCollection"/> 中添加项。
        /// </summary>
        /// <param name="value">要添加到 <see cref="ValueConfigurationCollection"/> 的对象。</param>
        /// <returns>新元素所插入到的位置,或为 <c>-1</c> 以指示未将该项插入到集合中。</returns>
        int IList.Add(object value)
        {
            var idx = Count;
            var str = value as string;

            if (str != null)
            {
                Add(str);
                return(idx);
            }
            var element = value as ValueConfigurationElement;

            if (element == null)
            {
                throw CommonExceptions.ArgumentWrongType(nameof(value));
            }
            BaseAdd(idx, element);
            return(idx);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 获取或设置指定索引处的元素。
 /// </summary>
 /// <param name="index">要获得或设置的元素从零开始的索引。</param>
 /// <value>指定索引处的元素。</value>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/>
 /// 不是 <see cref="ValueConfigurationCollection"/> 中的有效索引。</exception>
 object IList.this[int index]
 {
     get { return(this[index]); }
     set
     {
         var str = value as string;
         if (str != null)
         {
             this[index] = str;
             return;
         }
         var element = value as ValueConfigurationElement;
         if (element == null)
         {
             throw CommonExceptions.ArgumentWrongType(nameof(value));
         }
         base[index] = element;
     }
 }
        /// <summary>
        /// 向 <see cref="ValueConfigurationCollection"/> 中添加项。
        /// </summary>
        /// <param name="value">要添加到 <see cref="ValueConfigurationCollection"/> 的对象。</param>
        /// <returns>新元素所插入到的位置,或为 <c>-1</c> 以指示未将该项插入到集合中。</returns>
        int IList.Add(object value)
        {
            int    idx = this.Count;
            string str = value as string;

            if (str != null)
            {
                this.Add(str);
                return(idx);
            }
            ValueConfigurationElement element = value as ValueConfigurationElement;

            if (element == null)
            {
                throw CommonExceptions.ArgumentWrongType("value");
            }
            this.BaseAdd(idx, element);
            return(idx);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 将对象插入 <see cref="ListBase{T}"/> 的指定索引处。
 /// </summary>
 /// <param name="index">从零开始的索引,应在该位置插入 <paramref name="value"/>。</param>
 /// <param name="value">要插入到 <see cref="ListBase{T}"/> 中的对象。</param>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> 不是
 /// <see cref="ListBase{T}"/> 中的有效索引。</exception>
 /// <exception cref="ArgumentException"><paramref name="value"/> 不能赋值给
 /// <typeparamref name="T"/> 类型。</exception>
 void IList.Insert(int index, object value)
 {
     if (index < 0)
     {
         throw CommonExceptions.ArgumentNegative("index", index);
     }
     if (index > this.Count)
     {
         throw CommonExceptions.ArgumentOutOfRange("index", index);
     }
     Contract.EndContractBlock();
     try
     {
         this.InsertItem(index, (T)value);
     }
     catch (InvalidCastException)
     {
         throw CommonExceptions.ArgumentWrongType("value", value, typeof(T));
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 获取或设置指定索引处的元素。
 /// </summary>
 /// <param name="index">要获得或设置的元素从零开始的索引。</param>
 /// <value>指定索引处的元素。</value>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> 不是
 /// <see cref="ListBase{T}"/> 中的有效索引。</exception>
 /// <exception cref="ArgumentException">设置属性,且 <paramref name="value"/> 不能赋值给
 /// <typeparamref name="T"/> 类型。</exception>
 object IList.this[int index]
 {
     get
     {
         if (index < 0)
         {
             throw CommonExceptions.ArgumentNegative("index", index);
         }
         if (index > this.Count)
         {
             throw CommonExceptions.ArgumentOutOfRange("index", index);
         }
         Contract.EndContractBlock();
         return(this.GetItemAt(index));
     }
     set
     {
         if (index < 0)
         {
             throw CommonExceptions.ArgumentNegative("index", index);
         }
         if (index > this.Count)
         {
             throw CommonExceptions.ArgumentOutOfRange("index", index);
         }
         Contract.EndContractBlock();
         try
         {
             this.SetItemAt(index, (T)value);
         }
         catch (InvalidCastException)
         {
             throw CommonExceptions.ArgumentWrongType("value", value, typeof(T));
         }
     }
 }