PIBD14-BOYKO-M.S.SuperEasyS.../ProjectElectroTrans/Drawnings/DrawingTransCompareByType.cs

31 lines
805 B
C#
Raw Normal View History

2024-04-25 02:31:55 +04:00
namespace ProjectElectroTrans.Drawnings;
public class DrawingTransCompareByType : IComparer<DrawingTrans?>
{
public int Compare(DrawingTrans? x, DrawingTrans? y)
{
if (x == null && y == null) return 0;
if (x == null || x.EntityTrans == null)
{
return 1;
}
if (y == null || y.EntityTrans == null)
{
return -1;
}
if (x.GetType().Name != y.GetType().Name)
{
return x.GetType().Name.CompareTo(y.GetType().Name);
}
var speedCompare = x.EntityTrans.Speed.CompareTo(y.EntityTrans.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityTrans.Weight.CompareTo(y.EntityTrans.Weight);
}
}