/// <summary> /// Compares two specified Message objects and returns an integer that indicates their relationship to one another in the sort order /// </summary> /// <param name="wm1">The first Message</param> /// <param name="wm2">The second Message</param> /// <param name="ignoreText">True if the message text should be ignored when comparing Message objects</param> /// <returns> /// Less than zero if wm1 is less than wm2 /// Zero if wm1 is equal to wm2 /// Greater than zero if wm1 is greater than wm2 /// </returns> public static int Compare(Message wm1, Message wm2, bool ignoreText) { // cast the WixMessages to Objects for null comparison, otherwise the == operator call would be recursive Object obj1 = (Object)wm1; Object obj2 = (Object)wm2; if (null == obj1 && null == obj2) { // both objects are null return 0; } else if (null == obj1 && null != obj2) { // obj1 is null and obj2 is not null return -1; } else if (null != obj1 && null == obj2) { // obj1 is not null and obj1 is null return 1; } // wm1 and wm2 are both not null, so compare their values if (wm1.MessageNumber < wm2.MessageNumber) { return -1; } else if (wm1.MessageNumber > wm2.MessageNumber) { return 1; } else { // MessageNumbers are equal so compare MessageTypes if (wm1.MessageType != wm2.MessageType) { // MessageNumbers are equal but MessageTypes are not if (wm1.MessageType == MessageTypeEnum.Warning) { // A warning is considered to be 'less' than an error return -1; } else { return 1; } } else { // MessageNumbers and MessageTypes are equal so compare MessageText if (ignoreText) { return 0; } else { return String.Compare(wm1.MessageText, wm2.MessageText, StringComparison.InvariantCulture); } } } }
/// <summary> /// Compares two specified Message objects and returns an integer that indicates their relationship to one another in the sort order /// </summary> /// <param name="wm1">The first Message</param> /// <param name="wm2">The second Message</param> /// <returns> /// Less than zero if wm1 is less than wm2 /// Zero if wm1 is equal to wm2 /// Greater than zero if wm1 is greater than wm2 /// </returns> public static int Compare(Message wm1, Message wm2) { return Message.Compare(wm1, wm2, false); }