/// <summary> /// Compares the two DDAttributesCollection of the same values and returns an integer that indicates whether the current instance precedes. Very slow /// </summary> /// <param name="value1">First DDAttributesCollection to compare</param> /// <param name="value2">Second DDAttributesCollection to compare</param> /// <returns>A value that indicates the relative order of the objects being compared. The return value has two meanings: /// Zero - the both DDAttributesCollection have some items and their values. /// The difference between the number of elements of the first and second DDAttributes Collection /// One - values of collection is not equal.</returns> /// <remarks>The both null object is equal and return value will be Zero. Very slow</remarks> public static int Compare(DDAttributesCollection value1, DDAttributesCollection value2) { if (((object)value1 == null) && ((object)value2 == null)) { return(0); // if both are null -> return true } if (((object)value1 == null) || ((object)value2 == null)) { return(1); // if only one of them are null -> return false } if ((value1.Count != value2.Count)) { return(value1.Count - value2.Count); // The difference between the number of elements of the first and second DDAttributes Collection } foreach (var keyValue1 in value1) { if (!value2.Contains(keyValue1.Key)) { return(-1); // } var valueCompareResult = DDValue.Compare(keyValue1.Value, value2[keyValue1.Key]); if (valueCompareResult != 0) { return(valueCompareResult); } } return(0); }
/// <summary> /// Determines whether the Attribute Collection contains an elements with the specified names and will be throw new <exception cref="ContainsAttributesException"/> if one of these attributes was not found /// </summary> /// <param name="attr">collection of DDValue that can be accessed by name.</param> /// <param name="names">list of names of mandatory attributes</param> /// <exception cref="DDMissingSomeOfAttributesException"/> private static void containsAttributesOtherwiseThrow(this DDAttributesCollection attr, IEnumerable <string> names) { var nel = new List <string>(); foreach (var name in names) { if (!attr.Contains(name)) { nel.Add(name); } } if (nel.Count > 0) { throw new DDMissingSomeOfAttributesException(nel.ToArray()); } }