예제 #1
0
        public static void RemoveWithValue <Tk, Tv>(this Dict <Tk, Tv> dict, Tk key, Func <Tv, bool> remove)
            where Tk : IEquatable <Tk>
        {
            var values = dict.ValuesWithKey(key).ToArray();

            dict.RemoveAll(key);
            dict.AddRange(values.Where(v => !remove(v)).Select(v => new KeyValuePair <Tk, Tv>(key, v)));
        }
예제 #2
0
        public void TestAddRang()
        {
            var dict = new Dictionary <string, int>
            {
                { "1", 1 },
                { "2", 2 },
                { "3", 3 }
            };

            Dict.AddRange(dict, new Dictionary <string, int>
            {
                { "9", 9 },
                { "10", 10 }
            });

            ExceptionAssert.Throws(() =>
            {
                Dict.AddRange(dict, new Dictionary <string, int>
                {
                    { "9", 9 },
                    { "10", 10 }
                }, false);
            });

            Dict.AddRange(dict, new Dictionary <string, int>
            {
                { "10", 12 }
            });

            ExceptionAssert.DoesNotThrow(() =>
            {
                Dict.AddRange(dict, null);
            });

            Assert.AreEqual(true, dict.ContainsKey("9"));
            Assert.AreEqual(true, dict.ContainsKey("10"));
            Assert.AreEqual(12, dict["10"]);
        }
예제 #3
0
 /// <summary>
 /// 构建一个类型查询器引导
 /// </summary>
 /// <param name="assembly">需要添加的程序集</param>
 public BootstrapTypeFinder(IDictionary <string, int> assembly = null)
 {
     assemblies = new Dictionary <string, int>();
     Dict.AddRange(assemblies, Assemblys.Assembly);
     Dict.AddRange(assemblies, assembly);
 }