Example #1
0
        /// <summary>
        /// 使用指定的错误消息和对导致此异常的内部异常的引用初始化 <see cref="AggregateSourceException"/> 类的新实例。
        /// </summary>
        /// <param name="message">解释异常原因的错误消息。</param>
        /// <param name="innerExceptions">导致当前异常的异常。</param>
        private AggregateSourceException(string message, IList <SourceException> innerExceptions)
            : base(message, innerExceptions != null && innerExceptions.Count > 0 ? innerExceptions[0] : null)
        {
            CommonExceptions.CheckArgumentNull(innerExceptions, "innerExceptions");
            if (innerExceptions.Any(ex => ex == null))
            {
                throw CommonExceptions.CollectionItemNull("innerExceptions");
            }
            int cnt = innerExceptions.Count;

            this.innerExps = new SourceException[cnt];
            for (int i = 0; i < cnt; i++)
            {
                this.innerExps[i] = innerExceptions[i];
            }
            innerExpsCollection = new ReadOnlyCollection <SourceException>(this.innerExps);
        }
Example #2
0
        /// <summary>
        /// 使用指定的相等比较器、创建查找字典的阈值和被包装的列表,
        /// 初始化 <see cref="KeyedListBase{TKey, TItem}"/> 类的新实例。
        /// </summary>
        /// <param name="comparer">比较键时要使用的 <see cref="IEqualityComparer{T}"/> 泛型接口的实现,
        /// 如果为 <c>null</c>,则使用从 <see cref="EqualityComparer{T}.Default"/>
        /// 获取的该类型的键的默认相等比较器。</param>
        /// <param name="dictionaryCreationThreshold">在不创建查找字典的情况下列表可容纳的元素的数目
        /// (<c>0</c> 表示添加第一项时创建查找字典);或者为 <c>-1</c>,表示指定永远不会创建查找字典。</param>
        /// <param name="list">由新的列表包装的集合。</param>
        /// <remarks>如果 <paramref name="list"/> 实现了 <see cref="IList{T}"/>
        /// 接口,则使用 <paramref name="list"/> 作为内部集合;否则使用
        /// <see cref="List{T}"/> 作为内部集合。</remarks>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="dictionaryCreationThreshold"/> 小于 <c>-1</c>。</exception>
        protected KeyedListBase(IEqualityComparer <TKey> comparer, int dictionaryCreationThreshold,
                                IEnumerable <TItem> list)
            : base(list)
        {
            if (dictionaryCreationThreshold < -1)
            {
                throw CommonExceptions.InvalidThreshold("dictionaryCreationThreshold", dictionaryCreationThreshold);
            }
            this.comparer  = comparer ?? EqualityComparer <TKey> .Default;
            this.threshold = dictionaryCreationThreshold == -1 ? int.MaxValue : dictionaryCreationThreshold;
            int cnt = this.Items.Count;

            for (int i = 0; i < cnt; i++)
            {
                TItem item = this.Items[i];
                if (item == null)
                {
                    throw CommonExceptions.CollectionItemNull("list");
                }
                TKey key = this.GetKeyForItem(this.Items[i]);
                this.AddKey(key, this.Items[i]);
            }
        }
Example #3
0
        /// <summary>
        /// 使用指定的相等比较器、创建查找字典的阈值和被包装的列表,
        /// 初始化 <see cref="KeyedListBase{TKey, TItem}"/> 类的新实例。
        /// </summary>
        /// <param name="comparer">比较键时要使用的 <see cref="IEqualityComparer{T}"/> 泛型接口的实现,
        /// 如果为 <c>null</c>,则使用从 <see cref="EqualityComparer{T}.Default"/>
        /// 获取的该类型的键的默认相等比较器。</param>
        /// <param name="dictionaryCreationThreshold">在不创建查找字典的情况下列表可容纳的元素的数目
        /// (<c>0</c> 表示添加第一项时创建查找字典);或者为 <c>-1</c>,表示指定永远不会创建查找字典。</param>
        /// <param name="list">由新的列表包装的集合。</param>
        /// <remarks>如果 <paramref name="list"/> 实现了 <see cref="IList{T}"/>
        /// 接口,则使用 <paramref name="list"/> 作为内部集合;否则使用
        /// <see cref="List{T}"/> 作为内部集合。</remarks>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="dictionaryCreationThreshold"/> 小于 <c>-1</c>。</exception>
        protected KeyedListBase(IEqualityComparer <TKey> comparer, int dictionaryCreationThreshold,
                                IEnumerable <TItem> list)
            : base(list)
        {
            if (dictionaryCreationThreshold < -1)
            {
                throw CommonExceptions.InvalidThreshold(nameof(dictionaryCreationThreshold), dictionaryCreationThreshold);
            }
            this.comparer = comparer ?? EqualityComparer <TKey> .Default;
            threshold     = dictionaryCreationThreshold == -1 ? int.MaxValue : dictionaryCreationThreshold;
            var cnt = Items.Count;

            for (var i = 0; i < cnt; i++)
            {
                var item = Items[i];
                if (item == null)
                {
                    throw CommonExceptions.CollectionItemNull(nameof(list));
                }
                var key = GetKeyForItem(Items[i]);
                AddKey(key, Items[i]);
            }
        }