/// <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); }
/// <summary> /// Compares two <see cref="IRowViewModelBase{Thing}"/> of the same type /// </summary> /// <param name="x">The First <see cref="IRowViewModelBase{Thing}"/></param> /// <param name="y">The second <see cref="IRowViewModelBase{Thing}"/></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) { var xType = x.GetType(); var yType = y.GetType(); if (!PermissibleRowTypes.Contains(xType) || !PermissibleRowTypes.Contains(yType)) { throw new NotSupportedException("The list contains other types of row than the specified ones."); } var isxRowPrameterRow = typeof(ParameterOrOverrideBaseRowViewModel).IsAssignableFrom(xType); var isyRowParameterRow = typeof(ParameterOrOverrideBaseRowViewModel).IsAssignableFrom(yType); if ((isxRowPrameterRow && isyRowParameterRow) || (xType == yType)) { return(this.CompareSameType(x, y, yType)); } if (typeof(ParameterOrOverrideBaseRowViewModel).IsAssignableFrom(xType)) { return(-1); } // xtype is ParameterGroupRow, y parameterOrOverrideBase return(1); }
/// <summary> /// Tries to add values to a <see cref="List{T}"/> from a <see cref="IRowViewModelBase{Thing}"/> /// and its childrows /// </summary> /// <typeparam name="T"> /// The type of object the <see cref="List{T}"/> holds data for. /// </typeparam> /// <param name="rowViewModel"> /// The <see cref="IRowViewModelBase{Thing}"/> to be searched. /// </param> /// <param name="values"> /// The <see cref="List{T}"/> containing all the found values. /// </param> private void TryAddValuesFromRowViewModel <T>(IRowViewModelBase <Thing> rowViewModel, ref List <T> values) { var propInfo = rowViewModel.GetType().GetProperty(this.FieldName); if (propInfo != null) { var value = propInfo.GetValue(rowViewModel); if (value is T typedValue) { values.Add(typedValue); } } this.TryAddValuesFromRowViewModels(rowViewModel.ContainedRows, ref values); }
/// <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 (xType == yType) { return(this.CompareSameType(x, y, yType)); } if ((typeof(ParameterOrOverrideBaseRowViewModel).IsAssignableFrom(xType) || typeof(ParameterSubscriptionRowViewModel).IsAssignableFrom(xType)) && (typeof(ParameterOrOverrideBaseRowViewModel).IsAssignableFrom(yType) || typeof(ParameterSubscriptionRowViewModel).IsAssignableFrom(yType))) { return(this.CompareSameType(x, y, yType)); } if (typeof(ParameterOrOverrideBaseRowViewModel).IsAssignableFrom(xType) || typeof(ParameterSubscriptionRowViewModel).IsAssignableFrom(xType)) { return(-1); } if (typeof(ElementUsageRowViewModel).IsAssignableFrom(xType)) { return(1); } // x is a ParameterGroupRow if (typeof(ParameterOrOverrideBaseRowViewModel).IsAssignableFrom(yType) || typeof(ParameterSubscriptionRowViewModel).IsAssignableFrom(yType)) { return(1); } // x is ParameterGroupRow, y is ElementUsageRow return(-1); }
/// <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))) { throw new ArgumentException(string.Format("argument x is of type {0} which is not supported", xType.Name)); } if (!PermissibleRowTypes.Any(type => type.IsAssignableFrom(yType))) { throw new ArgumentException(string.Format("argument y is of type {0} which is not supported", yType.Name)); } return(BreadCrumbComparer.Compare((IBreadCrumb)x, (IBreadCrumb)y)); }