Пример #1
0
 /// <summary>
 /// Initializes a new instance of the OrderedCollection using an IComparer implementation.
 /// </summary>
 /// <param name="comparer">IComparer implementation used for the item comparisons during ordering</param>
 /// <param name="options">Options that control the behavior of the collection</param>
 public OrderedCollection(IComparer <T> comparer, OrderedCollectionOptions options)
 {
     if (comparer == null)
     {
         throw new ArgumentNullException("comparer");
     }
     _comparer = comparer;
     _options  = options ?? new OrderedCollectionOptions();
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the OrderedCollection class using a Comparison delegate for
 /// the comparison logic.
 /// </summary>
 /// <param name="comparison">The comparison delegate used for the item comparisons during ordering</param>
 /// <param name="options">Options that control the behavior of the collection</param>
 public OrderedCollection(Comparison <T> comparison, OrderedCollectionOptions options)
 {
     if (comparison == null)
     {
         throw new ArgumentNullException("comparison");
     }
     _comparer = new ComparisonComparer <T>(comparison);
     _options  = options ?? new OrderedCollectionOptions();
 }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the OrderedCollection
        /// </summary>
        /// <param name="options">Options that control the behavior of the collection</param>
        public OrderedCollection(OrderedCollectionOptions options)
        {
            Type comparableType = typeof(IComparable <>).MakeGenericType(typeof(T));

            if (!comparableType.IsAssignableFrom(typeof(T)))
            {
                throw new ArgumentException("Generic type should implement IComparable<>");
            }
            _comparer = new ComparableComparer <T>();
            _options  = options ?? new OrderedCollectionOptions();
        }