mirror of
https://github.com/SDRSharpR/SDRSharper.git
synced 2025-12-06 04:12:02 +01:00
32 lines
852 B
C#
32 lines
852 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Reflection;
|
|
|
|
namespace SDRSharp.FrequencyScanner
|
|
{
|
|
public class SortableBindingListComparer<T> : IComparer<T>
|
|
{
|
|
private PropertyInfo _sortProperty;
|
|
|
|
private ListSortDirection _sortDirection;
|
|
|
|
public SortableBindingListComparer(string sortProperty, ListSortDirection sortDirection)
|
|
{
|
|
this._sortProperty = typeof(T).GetProperty(sortProperty);
|
|
this._sortDirection = sortDirection;
|
|
}
|
|
|
|
public int Compare(T x, T y)
|
|
{
|
|
IComparable comparable = (IComparable)this._sortProperty.GetValue(x, null);
|
|
IComparable comparable2 = (IComparable)this._sortProperty.GetValue(y, null);
|
|
if (this._sortDirection == ListSortDirection.Ascending)
|
|
{
|
|
return comparable.CompareTo(comparable2);
|
|
}
|
|
return comparable2.CompareTo(comparable);
|
|
}
|
|
}
|
|
}
|