/// <summary> /// Compares two <see cref="RequirementsSpecification"/> /// </summary> /// <param name="x">The first <see cref="RequirementsSpecification"/> to compare</param> /// <param name="y">The second <see cref="RequirementsSpecification"/> to compare</param> /// <returns> /// Less than zero : x is "lower" than y /// Zero: x "equals" y. /// Greater than zero: x is "greater" than y. /// </returns> public int Compare(IRowViewModelBase <Thing> x, IRowViewModelBase <Thing> y) { if (x == null || y == null) { throw new ArgumentNullException(); } var xspec = x.Thing as RequirementsSpecification; var yspec = y.Thing as RequirementsSpecification; if (xspec == null || yspec == null) { return(0); } if (RequirementsModule.PluginSettings?.OrderSettings != null && RequirementsModule.PluginSettings.OrderSettings.ParameterType != Guid.Empty) { var xOrder = xspec.ParameterValue.FirstOrDefault(z => z.ParameterType.Iid == RequirementsModule.PluginSettings.OrderSettings.ParameterType)?.Value.FirstOrDefault(); var yOrder = yspec.ParameterValue.FirstOrDefault(z => z.ParameterType.Iid == RequirementsModule.PluginSettings.OrderSettings.ParameterType)?.Value.FirstOrDefault(); int xOrderKey, yOrderKey; if (xOrder != null && int.TryParse(xOrder, out xOrderKey) && yOrder != null && int.TryParse(yOrder, out yOrderKey)) { return(xOrderKey > yOrderKey ? 1 : xOrderKey < yOrderKey ? -1 : shortNameThingComparer.Compare(xspec, yspec)); } return(shortNameThingComparer.Compare(xspec, yspec)); } return(shortNameThingComparer.Compare(xspec, yspec)); }
/// <summary> /// Compares two <see cref="IRowViewModelBase{Thing}"/> /// </summary> /// <param name="x">The first <see cref="IRowViewModelBase{Thing}"/> to compare</param> /// <param name="y">The second <see cref="IRowViewModelBase{Thing}"/> to compare</param> /// <returns> /// Less than zero : x is "lower" than y /// Zero: x "equals" y. /// Greater than zero: x is "greater" than y. /// </returns> public int Compare(IRowViewModelBase <Thing> x, IRowViewModelBase <Thing> y) { if (x == null || y == null) { throw new ArgumentNullException(); } var xType = x.GetType(); var yType = y.GetType(); if (!PermissibleRowTypes.Any(type => type.IsAssignableFrom(xType)) || !PermissibleRowTypes.Any(type => type.IsAssignableFrom(yType))) { throw new NotSupportedException("The list contains other types of row than the specified ones."); } if (typeof(RequirementRowViewModel).IsAssignableFrom(xType) && typeof(RequirementsGroupRowViewModel).IsAssignableFrom(yType)) { return(-1); } if (typeof(RequirementsGroupRowViewModel).IsAssignableFrom(xType) && typeof(RequirementRowViewModel).IsAssignableFrom(yType)) { return(1); } if (xType == yType) { return(shortNameThingComparer.Compare((IShortNamedThing)x.Thing, (IShortNamedThing)y.Thing)); } // x is a group, y is ElementUsageRow return(1); }