43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WebWindowComplex
|
|
{
|
|
public class DictUtils
|
|
{
|
|
/// <summary>
|
|
/// Comparatore equality obj dizionario
|
|
/// </summary>
|
|
/// <typeparam name="TKey"></typeparam>
|
|
/// <typeparam name="TValue"></typeparam>
|
|
/// <param name="dict1"></param>
|
|
/// <param name="dict2"></param>
|
|
/// <returns></returns>
|
|
public static bool DictAreEqual<TKey, TValue>(Dictionary<TKey, TValue> dict1, Dictionary<TKey, TValue> dict2)
|
|
{
|
|
// Handle null cases
|
|
if (dict1 == null || dict2 == null)
|
|
return dict1 == dict2;
|
|
|
|
// Quick size check
|
|
if (dict1.Count != dict2.Count)
|
|
return false;
|
|
|
|
// Compare each key-value pair
|
|
foreach (var kvp in dict1)
|
|
{
|
|
if (!dict2.TryGetValue(kvp.Key, out TValue value))
|
|
return false; // Key missing in dict2
|
|
|
|
if (!EqualityComparer<TValue>.Default.Equals(kvp.Value, value))
|
|
return false; // Value mismatch
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|