public static void TestAdd() { DualKeyDictionary <int, int, string> dict = new DualKeyDictionary <int, int, string>(); dict.Add(0, 0, "0,0"); dict.Add(0, 1, "0,1"); dict.Add(1, 0, "1,0"); dict.Add(1, 1, "1,1"); Assert.AreEqual(dict.Count, 4); Assert.IsTrue(dict.ContainsKey(1, 1)); Assert.AreEqual(dict[1, 1], "1,1"); }
/// <summary> /// Given a DualKeyDictionary with a key pair of type ( <typeparamref name="T1" />, /// <typeparamref name="T2"></typeparamref>), which maps to a value that is an enumeration over elements of type /// <typeparamref name="T4" />, return true iff there is an key entry consisting of the pair ( /// <paramref name="keyPart1" />, <paramref name="keyPart2" />) that has a non-null and non-empty key. /// </summary> /// <typeparam name="T1">The type of the first element of the paired key</typeparam> /// <typeparam name="T2">The type of the second element of the paired key.</typeparam> /// <typeparam name="T3">The type of the enumeration that is the value of the dictionary.</typeparam> /// <typeparam name="T4">The type of the elements inside the enumeration value.</typeparam> /// <param name="dict">The dual-key dictionary that we're checking for a key pair (with a nonempty and nonnull value)</param> /// <param name="keyPart1">The first item of the paired key.</param> /// <param name="keyPart2">The second item of the paired key.</param> /// <returns> /// true iff there is an key entry consisting of the pair ( <paramref name="keyPart1" />, /// <paramref name="keyPart2" />) that has a non-null and non-empty key. /// </returns> public static bool ContainsKeyNonEmptyNotNullValue <T1, T2, T3, T4>(this DualKeyDictionary <T1, T2, T3> dict, T1 keyPart1, T2 keyPart2) where T3 : HashSet <T4> { // Return false if the key doesn't exist. if (!dict.ContainsKey(keyPart1, keyPart2)) { return(false); } // Return a value associated not just with checking if the value <keyPart1, keyPart2> is // in the Dictionary, and that its value is non-null and non-empty. T3 dictValue = dict[keyPart1, keyPart2]; return(dictValue != null && !dictValue.IsEmpty()); }