private static void TrySetComparer(CollectionViewSource source, IComparer?comparer) { if (source.View is ListCollectionView listView) { listView.CustomSort = comparer; } }
// 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; } }
/// <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); } }
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; }
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; }
// 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; }
/// <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); }
public NameValueCollection(int capacity, IHashCodeProvider?hashProvider, IComparer?comparer) : base(capacity, hashProvider, comparer) { }
public NameValueCollection(IHashCodeProvider?hashProvider, IComparer?comparer) : base(hashProvider, comparer) { }
// 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 });
public static void SetSortComparer(GridViewColumn column, IComparer?value) => column.SetValue(SortComparerProperty, value);
internal CompatibleComparer(IHashCodeProvider?hashCodeProvider, IComparer?comparer) { _hcp = hashCodeProvider; _comparer = comparer; }
public static void SetComparer(CollectionViewSource source, IComparer?value) => source?.SetValue(ViewSort.ComparerProperty, value);
/// <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)); }
/// <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)); }
/// <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);
/// <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);
protected NameObjectCollectionBase(int capacity, IHashCodeProvider?hashProvider, IComparer?comparer) { _keyComparer = new CompatibleComparer(hashProvider, comparer); Reset(capacity); }
public ListDictionary(IComparer?comparer) { this.comparer = comparer; }
// 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; }
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(); }