/// <summary>
        ///
        /// </summary>
        /// <typeparam name="Tkey"></typeparam>
        /// <typeparam name="TVal"></typeparam>
        /// <param name="prestring"></param>
        /// <param name="d1"></param>
        /// <param name="d2"></param>
        /// <param name="ans"></param>
        /// <param name="compareValues"></param>
        /// <returns></returns>
        private static bool CompareDictionaries <Tkey, TVal>(string prestring, Dictionary <Tkey, TVal> d1, Dictionary <Tkey, TVal> d2, List <SequenceDifference> ans,
                                                             compareItems <TVal> compareValues)
        {
            if (onewayKeyCompare <Tkey, TVal>(prestring, d1, d2, ans))
            {
                return(true);
            }
            if (onewayKeyCompare <Tkey, TVal>(prestring, d2, d1, ans))
            {
                return(true);
            }

            bool diff = false;

            foreach (Tkey key in d1.Keys)
            {
                TVal valA, valB;
                valA = d1[key];
                valB = d2[key];

                diff |= compareValues(prestring + " Item [" + key.ToString() + "]: ", valA, valB, ans);
            }

            return(diff);
        }
        private static bool CompareGroups <TChannelType>(string preString, Group <TChannelType> a, Group <TChannelType> b, List <SequenceDifference> ans,
                                                         compareItems <TChannelType> compareChannelData) where TChannelType : new()
        {
            if (a.GroupName != b.GroupName)
            {
                ans.Add(new SequenceDifference(preString + "names differ " + a.GroupName + "vs. " + b.GroupName + " skipping details comparison."));
                return(true);
            }

            return(CompareDictionaries <int, TChannelType>(preString + a.GroupName + " channel data :",
                                                           a.ChannelDatas, b.ChannelDatas, ans, compareChannelData));
        }
        /// <summary>
        /// Compares two lists of any type of object, given a method for comparing the objects themselves.
        /// </summary>
        /// <typeparam name="TVal"></typeparam>
        /// <param name="prestring"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="ans"></param>
        /// <param name="compareValues"></param>
        /// <returns></returns>
        private static bool CompareLists <TVal>(string prestring, List <TVal> a, List <TVal> b, List <SequenceDifference> ans,
                                                compareItems <TVal> compareValues)
        {
            if (a.Count != b.Count)
            {
                ans.Add(new SequenceDifference(prestring + "Lists different length. Skipping comparison."));
                return(true);
            }

            bool diffs = false;

            for (int i = 0; i < a.Count; i++)
            {
                TVal valA, valB;
                valA   = a[i];
                valB   = b[i];
                diffs |= compareValues(prestring + "Item #" + i + "[" + valA.ToString() + "]: ", valA, valB, ans);
            }
            return(diffs);
        }
        private static bool CompareObjectArray <TType>(string preString, TType[] ar1, TType[] ar2, List <SequenceDifference> ans, compareItems <TType> compareItemsMethod) where TType : new()
        {
            if (ar1 == null || ar2 == null)
            {
                if ((ar1 == null) & (ar2 == null))
                {
                    return(false);
                }
                else
                {
                    addDifference(preString + "one array null, other not.", ans);
                    return(true);
                }
            }

            if (ar1.Length != ar2.Length)
            {
                addDifference(preString + "different lengths.", ans);
                return(true);
            }

            bool diffs = false;

            for (int i = 0; i < ar1.Length; i++)
            {
                diffs |= compareItemsMethod(preString + "element #" + i + " ", ar1[i], ar2[i], ans);
            }
            return(diffs);
        }