35 lines
969 B
C#
35 lines
969 B
C#
|
namespace ProjectElectroTrans.Drawnings;
|
|||
|
|
|||
|
public class DrawingTransCompareByColor : 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 (ToHex(x.EntityTrans.BodyColor) != ToHex(y.EntityTrans.BodyColor))
|
|||
|
{
|
|||
|
return String.Compare(ToHex(x.EntityTrans.BodyColor), ToHex(y.EntityTrans.BodyColor),
|
|||
|
StringComparison.Ordinal);
|
|||
|
}
|
|||
|
|
|||
|
var speedCompare = x.EntityTrans.Speed.CompareTo(y.EntityTrans.Speed);
|
|||
|
if (speedCompare != 0)
|
|||
|
{
|
|||
|
return speedCompare;
|
|||
|
}
|
|||
|
|
|||
|
return x.EntityTrans.Weight.CompareTo(y.EntityTrans.Weight);
|
|||
|
}
|
|||
|
|
|||
|
private static String ToHex(Color c)
|
|||
|
=> $"#{c.R:X2}{c.G:X2}{c.B:X2}";
|
|||
|
}
|