SDRSharper/Plugins/SDRSharper.FrequencyScanner/SDRSharp.FrequencyScanner/SortableBindingListComparer.cs
SDRSharpR c07e6e6034 SDRSharper (SDRSharp Remake) Full Source (VS2017)
SDRSharper (SDRSharp Remake) Full Source (VS2017)
2018-03-26 14:02:05 -07:00

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);
}
}
}