public ModelItemDictionaryImpl(ModelTreeManager modelTreeManager, Type itemType, Object instance, ModelItem parent)
        {
            Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null");
            Fx.Assert(itemType != null, "item type cannot be null");
            Fx.Assert(instance != null, "instance cannot be null");
            this.itemType = itemType;
            this.instance = new DictionaryWrapper(instance);
            this.modelTreeManager = modelTreeManager;
            this.parents = new List<ModelItem>(1);
            this.sources = new List<ModelProperty>(1);
            this.helper = new ModelTreeItemHelper();
            if (parent != null)
            {
                this.manuallySetParent = parent;
            }
            this.modelPropertyStore = new Dictionary<string, ModelItem>();
            this.subTreeNodesThatNeedBackLinkPatching = new List<ModelItem>();
            this.modelItems = new NullableKeyDictionary<ModelItem, ModelItem>();
            UpdateInstance();


            if (ItemsCollectionObject != null)
            {
                ItemsCollectionModelItemCollection.CollectionChanged += new NotifyCollectionChangedEventHandler(itemsCollection_CollectionChanged);
                this.ItemsCollectionObject.ModelDictionary = this;
            }
        }
Esempio n. 2
0
        public ModelItemDictionaryImpl(ModelTreeManager modelTreeManager, Type itemType, Object instance, ModelItem parent)
        {
            Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null");
            Fx.Assert(itemType != null, "item type cannot be null");
            Fx.Assert(instance != null, "instance cannot be null");
            this.itemType         = itemType;
            this.instance         = new DictionaryWrapper(instance);
            this.modelTreeManager = modelTreeManager;
            this.parents          = new List <ModelItem>(1);
            this.sources          = new List <ModelProperty>(1);
            this.helper           = new ModelTreeItemHelper();
            if (parent != null)
            {
                this.manuallySetParent = parent;
            }
            this.modelPropertyStore = new Dictionary <string, ModelItem>();
            this.subTreeNodesThatNeedBackLinkPatching = new List <ModelItem>();
            this.modelItems = new NullableKeyDictionary <ModelItem, ModelItem>();
            UpdateInstance();


            if (ItemsCollectionObject != null)
            {
                ItemsCollectionModelItemCollection.CollectionChanged += new NotifyCollectionChangedEventHandler(itemsCollection_CollectionChanged);
                this.ItemsCollectionObject.ModelDictionary            = this;
            }
        }
        public void TestNullableKeyDictionaryInt()
        {
            var dict = new NullableKeyDictionary <int?, string> {
                { 1, "Hello" },
                { null, "Null" }
            };

            Assert.AreEqual(2, dict.Count);
        }
        public void TestNullableKeyDictionaryString()
        {
            var dict = new NullableKeyDictionary <string, string> {
                { "Hello", "World" },
                { null, "Null" }
            };

            Assert.AreEqual(2, dict.Count);
        }
        public void TestNullableKeyDictionaryContainsKey()
        {
            var dict = new NullableKeyDictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "Hello", "World" },
                { null, "Null" }
            };

            Assert.IsTrue(dict["hello"] == dict["Hello"]);
            Assert.IsTrue(dict.ContainsKey("hello"));
            Assert.IsTrue(dict.ContainsKey(null));
        }
        public void TestNullableKeyDictionaryKeys()
        {
            var dict = new NullableKeyDictionary <string, string> {
                { "Hello", "World" },
                { null, "Null" }
            };
            var keys  = dict.Keys;
            var keys1 = new String[2];

            keys.CopyTo(keys1, 0);
            var keys2 = new String[] { "Hello", null };

            Assert.IsTrue(keys1.SequenceEqual(keys2));
        }
        public void NullableKeyDictionaryTest()
        {
            int value = 0;
            IDictionary <string, int> target = new NullableKeyDictionary <string, int>();

            target.Add(null, 13);
            target.Add(new KeyValuePair <string, int>("a", 14));
            Assert.IsTrue(target.ContainsKey(null));
            Assert.IsTrue(target.ContainsKey("a"));
            Assert.IsTrue(target.Contains(new KeyValuePair <string, int>(null, 13)));
            Assert.IsTrue(target.Contains(new KeyValuePair <string, int>("a", 14)));
            Assert.IsTrue(target.Keys.Contains(null));
            Assert.IsTrue(target.Keys.Contains("a"));
            Assert.IsTrue(target.Values.Contains(13));
            Assert.IsTrue(target.Values.Contains(14));
            Assert.AreEqual(target.Count, 2);

            Assert.IsTrue(target.TryGetValue(null, out value));
            Assert.AreEqual(value, 13);
            Assert.IsTrue(target.TryGetValue("a", out value));
            Assert.AreEqual(value, 14);

            foreach (KeyValuePair <string, int> item in target)
            {
                Console.WriteLine(item);
            }

            Assert.IsTrue(target.Remove(null));
            Assert.IsFalse(target.Remove(new KeyValuePair <string, int>(null, 13)));
            Assert.IsTrue(target.Remove("a"));
            Assert.IsFalse(target.Remove(new KeyValuePair <string, int>("a", 14)));

            foreach (KeyValuePair <string, int> item in target)
            {
                Console.WriteLine(item);
            }
        }
Esempio n. 8
0
 internal Lookup(IEqualityComparer <TKey> comparer)
 {
     mKeyGroupPairs = new NullableKeyDictionary <TKey, IGrouping <TKey, TElement> >(comparer);
 }