Libation/LibationWinForms/ObjectMemberComparer[T].cs
Michael Bucari-Tovo ef35c2aee9 Code Cleanup
2021-08-10 16:15:32 -06:00

22 lines
606 B
C#

using System.Collections.Generic;
using System.ComponentModel;
namespace LibationWinForms
{
internal class ObjectMemberComparer<T> : IComparer<T> where T : IObjectMemberComparable
{
public ListSortDirection Direction { get; set; } = ListSortDirection.Ascending;
public string PropertyName { get; set; }
public int Compare(T x, T y)
{
var val1 = x.GetMemberValue(PropertyName);
var val2 = y.GetMemberValue(PropertyName);
return DirMult * x.GetMemberComparer(val1.GetType()).Compare(val1, val2);
}
private int DirMult => Direction == ListSortDirection.Descending ? -1 : 1;
}
}