/// <summary> /// Decides the order to use. This overrides the users settings when certain situations arise e.g. two <see cref="IOrderable"/> objects are /// next to each other in the tree at the same branch (in this case reordering them could be very confusing to the user). /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public int Compare(object x, object y) { //Use IOrderable.Order if (x is IOrderable xOrderable && y is IOrderable yOrderable) { return(xOrderable.Order - yOrderable.Order); } if (x is IOrderable xOnly) { return(xOnly.Order); } // The comparison is reversed (y is orderable) so the order must be negated to. if (y is IOrderable yOnly) { return(-yOnly.Order); } //or use whatever the model is if (_modelComparer != null) { return(_modelComparer.Compare(x, y)); } return(string.Compare(x.ToString(), y.ToString())); }
/// <summary> /// Decides the order to use. This overrides the users settings when certain situations arise e.g. two <see cref="IOrderable"/> objects are /// next to each other in the tree at the same branch (in this case reordering them could be very confusing to the user). /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public int Compare(object x, object y) { //Use IOrderable.Order if (x is IOrderable xOrderable && y is IOrderable yOrderable) { return(xOrderable.Order - yOrderable.Order); } //or use whatever the model is if (_modelComparer != null) { return(_modelComparer.Compare(x, y)); } return(string.Compare(x.ToString(), y.ToString())); }