예제 #1
0
 private static void TrySetComparer(CollectionViewSource source, IComparer?comparer)
 {
     if (source.View is ListCollectionView listView)
     {
         listView.CustomSort = comparer;
     }
 }
예제 #2
0
 // Constructs a new sorted list with a given IComparer
 // implementation. The sorted list is initially empty and has a capacity of
 // zero. Upon adding the first element to the sorted list the capacity is
 // increased to 16, and then increased in multiples of two as required. The
 // elements of the sorted list are ordered according to the given
 // IComparer implementation. If comparer is null, the
 // elements are compared to each other using the IComparable
 // interface, which in that case must be implemented by the keys of all
 // entries added to the sorted list.
 //
 public SortedList(IComparer?comparer)
     : this()
 {
     if (comparer != null)
     {
         this.comparer = comparer;
     }
 }
예제 #3
0
 /// <summary>
 /// Sorts the members of this EventDescriptorCollection using the specified IComparer.
 /// </summary>
 protected void InternalSort(IComparer?sorter)
 {
     if (sorter == null)
     {
         TypeDescriptor.SortDescriptorArray(this);
     }
     else
     {
         Array.Sort(_events, sorter);
     }
 }
예제 #4
0
 private EventDescriptorCollection(EventDescriptor?[] events, int eventCount, string[]?namedSort, IComparer?comparer)
 {
     _eventsOwned = false;
     if (namedSort != null)
     {
         _namedSort = (string[])namedSort.Clone();
     }
     _comparer = comparer;
     _events   = events;
     Count     = eventCount;
     _needSort = true;
 }
예제 #5
0
 private PropertyDescriptorCollection(PropertyDescriptor[] properties, int propCount, string[]?namedSort, IComparer?comparer)
 {
     _propsOwned = false;
     if (namedSort != null)
     {
         _namedSort = (string[])namedSort.Clone();
     }
     _comparer   = comparer;
     _properties = properties;
     Count       = propCount;
     _needSort   = true;
 }
예제 #6
0
        // Constructs a new sorted list containing a copy of the entries in the
        // given dictionary. The elements of the sorted list are ordered according
        // to the given IComparer implementation. If comparer is
        // null, the elements are compared to each other using the
        // IComparable interface, which in that case must be implemented
        // by the keys of all entries in the given dictionary as well as keys
        // subsequently added to the sorted list.
        //
        public SortedList(IDictionary d, IComparer?comparer)
            : this(comparer, d?.Count ?? throw new ArgumentNullException(nameof(d)))
        {
            d.Keys.CopyTo(keys, 0);
            d.Values.CopyTo(values, 0);

            // Array.Sort(Array keys, Array values, IComparer comparer) does not exist in System.Runtime contract v4.0.10.0.
            // This works around that by sorting only on the keys and then assigning values accordingly.
            Array.Sort(keys, comparer);
            for (int i = 0; i < keys.Length; i++)
            {
                values[i] = d[keys[i]];
            }
            _size = d.Count;
        }
예제 #7
0
        /// <summary>
        /// Gets a collection of standard values for the data type this validator is
        /// designed for.
        /// </summary>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext?context)
        {
            if (Values == null)
            {
                // We need to get the enum values in this rather round-about way so we can filter
                // out fields marked Browsable(false). Note that if multiple fields have the same value,
                // the behavior is undefined, since what we return are just enum values, not names.
                Type reflectType = TypeDescriptor.GetReflectionType(EnumType) ?? EnumType;

                FieldInfo[]? fields = reflectType.GetFields(BindingFlags.Public | BindingFlags.Static);
                ArrayList?objValues = null;

                if (fields != null && fields.Length > 0)
                {
                    objValues = new ArrayList(fields.Length);
                }

                if (objValues != null)
                {
                    foreach (FieldInfo field in fields !)
                    {
                        BrowsableAttribute?browsableAttr = null;
                        foreach (Attribute attr in field.GetCustomAttributes(typeof(BrowsableAttribute), false))
                        {
                            browsableAttr = attr as BrowsableAttribute;
                        }

                        if (browsableAttr == null || browsableAttr.Browsable)
                        {
                            object?value = null;

                            try
                            {
                                if (field.Name != null)
                                {
                                    value = Enum.Parse(EnumType, field.Name);
                                }
                            }
                            catch (ArgumentException)
                            {
                                // Hmm, for some reason, the parse threw. Let us ignore this value.
                            }

                            if (value != null)
                            {
                                objValues.Add(value);
                            }
                        }
                    }

                    IComparer?comparer = Comparer;
                    if (comparer != null)
                    {
                        objValues.Sort(comparer);
                    }
                }

                Array?arr = objValues?.ToArray();
                Values = new StandardValuesCollection(arr);
            }
            return(Values);
        }
예제 #8
0
 public NameValueCollection(int capacity, IHashCodeProvider?hashProvider, IComparer?comparer)
     : base(capacity, hashProvider, comparer)
 {
 }
예제 #9
0
 public NameValueCollection(IHashCodeProvider?hashProvider, IComparer?comparer)
     : base(hashProvider, comparer)
 {
 }
예제 #10
0
 // Constructs a new sorted list with a given IComparer
 // implementation and a given initial capacity. The sorted list is
 // initially empty, but will have room for the given number of elements
 // before any reallocations are required. The elements of the sorted list
 // are ordered according to the given IComparer implementation. If
 // comparer is null, the elements are compared to each other using
 // the IComparable interface, which in that case must be implemented
 // by the keys of all entries added to the sorted list.
 //
 public SortedList(IComparer?comparer, int capacity)
     : this(comparer)
 {
     // ReSharper disable once VirtualMemberCallInConstructor
     Capacity = capacity;
 }
 public static IEnumerable <T>?OrderBy <T, TKey>(this IEnumerable <T> source, Func <T, TKey> keySelector, DataGridSortDirection direction, IComparer?comparer)
 {
     return(direction switch
     {
         DataGridSortDirection.Ascending => source.OrderBy(keySelector, new ComparerWrapper <TKey>(comparer)),
         DataGridSortDirection.Descending => source.OrderByDescending(keySelector, new ComparerWrapper <TKey>(comparer)),
         _ => source
     });
예제 #12
0
 public static void SetSortComparer(GridViewColumn column, IComparer?value) => column.SetValue(SortComparerProperty, value);
예제 #13
0
 internal CompatibleComparer(IHashCodeProvider?hashCodeProvider, IComparer?comparer)
 {
     _hcp      = hashCodeProvider;
     _comparer = comparer;
 }
예제 #14
0
 public static void SetComparer(CollectionViewSource source, IComparer?value) => source?.SetValue(ViewSort.ComparerProperty, value);
예제 #15
0
 /// <summary>
 /// Sorts the members of this PropertyDescriptorCollection, using the specified IComparer to compare,
 /// the PropertyDescriptors contained in the collection.
 /// </summary>
 public virtual PropertyDescriptorCollection Sort(IComparer?comparer)
 {
     return(new PropertyDescriptorCollection(_properties, Count, _namedSort, comparer));
 }
예제 #16
0
 /// <summary>
 /// Sorts the members of this PropertyDescriptorCollection. Any specified NamedSort arguments will
 /// be applied first, followed by sort using the specified IComparer.
 /// </summary>
 public virtual PropertyDescriptorCollection Sort(string[]?names, IComparer?comparer)
 {
     return(new PropertyDescriptorCollection(_properties, Count, names, comparer));
 }
예제 #17
0
 /// <inheritdoc cref="Array.Sort(Array,Array,int,int,IComparer)"/>
 public static void Sort(this Array keys, Array?items = null, int index = 0, int?length = null, IComparer?comparer = null) =>
 Array.Sort(keys, items, index, length ?? keys.Length - index, comparer);
예제 #18
0
 /// <inheritdoc cref="Array.BinarySearch(Array,int,int,object,IComparer)"/>
 public static int BinarySearch(this Array array, object?value, int index = 0, int?length = null, IComparer?comparer = null) =>
 Array.BinarySearch(array, index, length ?? array.Length - index, value, comparer);
예제 #19
0
 protected NameObjectCollectionBase(int capacity, IHashCodeProvider?hashProvider, IComparer?comparer)
 {
     _keyComparer = new CompatibleComparer(hashProvider, comparer);
     Reset(capacity);
 }
예제 #20
0
 public ListDictionary(IComparer?comparer)
 {
     this.comparer = comparer;
 }
예제 #21
0
 // Constructs a new sorted list with a given IComparer
 // implementation and a given initial capacity. The sorted list is
 // initially empty, but will have room for the given number of elements
 // before any reallocations are required. The elements of the sorted list
 // are ordered according to the given IComparer implementation. If
 // comparer is null, the elements are compared to each other using
 // the IComparable interface, which in that case must be implemented
 // by the keys of all entries added to the sorted list.
 //
 public SortedList(IComparer?comparer, int capacity)
     : this(comparer)
 {
     Capacity = capacity;
 }
예제 #22
0
 public void SetColumnSortDirection(string column, DataGridSortDirection direction, IComparer?comparer)
 {
     if (direction != DataGridSortDirection.None)
     {
         DisplayItems = Items?.OfType <object>()?.OrderBy(item => item.GetType().GetProperty(column)?.GetValue(item), direction, comparer);
     }
     else
     {
         DisplayItems = Items;
     }
     ColumnSorted?.Invoke(this, column);
     StateHasChanged();
 }