Esempio n. 1
0
        /// <summary>
        /// Finds the duplicates in the list and returns count.
        /// </summary>
        /// <typeparam name="T">The type of the item.</typeparam>
        /// <param name="list">The list of items.</param>
        /// <param name="compareItemFunc">The function that is used to compare the items.</param>
        /// <returns>The duplicates count.</returns>
        public static int GetDuplicatesCountForUnsortedList <T>(this List <T> list, CompareItemFunc <T> compareItemFunc)
        {
            int duplicatesCount = 0;

            if (list?.Count > 1)
            {
                var clonedList = new List <T>(list);

                for (int i = 0; i < clonedList.Count; i++)
                {
                    for (int j = i + 1; j < clonedList.Count; j++)
                    {
                        if (compareItemFunc(clonedList[i], clonedList[j]) == MatchComparisonResultType.Same)
                        {
                            duplicatesCount++;

                            clonedList.RemoveAt(j);
                            j--;
                        }
                    }
                }
            }

            return(duplicatesCount);
        }
 /// <summary>
 /// Sets the CompareItemFunc.
 /// </summary>
 /// <typeparam name="TKey">The type of the key.</typeparam>
 /// <typeparam name="TItem">The type of the item.</typeparam>
 /// <param name="syncAgent">The sync agent.</param>
 /// <param name="compareItemFunc">The compare item function compares two items and determines if they are the same, one of them is newer, or there is a conflict.</param>
 /// <returns></returns>
 public static IBatchSyncAgent <TKey, TItem> SetCompareItemFunc <TKey, TItem>(this IBatchSyncAgent <TKey, TItem> syncAgent, CompareItemFunc <TItem> compareItemFunc)
 {
     syncAgent.CompareItemFunc = compareItemFunc;
     return(syncAgent);
 }
 /// <summary>
 /// Sets the CompareItemFunc.
 /// </summary>
 /// <typeparam name="TKey">The type of the key.</typeparam>
 /// <typeparam name="TItem">The type of the item.</typeparam>
 /// <param name="comparerAgent">The comparer agent.</param>
 /// <param name="compareItemFunc">The compare item function compares two items and determines if they are the same, one of them is newer, or there is a conflict.</param>
 /// <returns>The comparer agent.</returns>
 public static IComparerAgent <TKey, TItem> SetCompareItemFunc <TKey, TItem>(this IComparerAgent <TKey, TItem> comparerAgent, CompareItemFunc <TItem> compareItemFunc)
 {
     comparerAgent.CompareItemFunc = compareItemFunc;
     return(comparerAgent);
 }