DictionaryExtensions.cs (2047B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="DictionaryExtensions.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.Management.Configuration.Processor.Extensions 8 { 9 using System; 10 using System.Collections; 11 using System.Collections.Generic; 12 using Windows.Foundation.Collections; 13 14 /// <summary> 15 /// Extensions for dictionaries. 16 /// </summary> 17 internal static class DictionaryExtensions 18 { 19 /// <summary> 20 /// Performs a deep compare of the dictionaries. 21 /// </summary> 22 /// <param name="first">First dictionary.</param> 23 /// <param name="second">Second dictionary.</param> 24 /// <returns>Whether the two dictionaries equal.</returns> 25 internal static bool ContentEquals(this IDictionary<string, string> first, IDictionary<string, string> second) 26 { 27 if (first.Count != second.Count) 28 { 29 return false; 30 } 31 32 foreach (var keyValuePair in first) 33 { 34 string key = keyValuePair.Key; 35 if (!second.ContainsKey(key)) 36 { 37 return false; 38 } 39 40 var firstValue = keyValuePair.Value; 41 var secondValue = second[key]; 42 43 // Empty value check. 44 if (firstValue == null && secondValue == null) 45 { 46 continue; 47 } 48 else if (firstValue == null || secondValue == null) 49 { 50 return false; 51 } 52 53 if (firstValue != secondValue) 54 { 55 return false; 56 } 57 } 58 59 return true; 60 } 61 } 62 }