Exemplo n.º 1
0
        public ObservableList(bool shouldHook, params T[] initialValues)
        {
            _list = initialValues.ToList();
            _shouldHookNestedObservables = shouldHook && PossibleObservableHelpers.IsObservable(typeof(T));

            // Note: The HookValue method will also check these conditions but we can save ourselve the enumeration if we know that we don't care about hooking nested lists
            if (_shouldHookNestedObservables)
            {
                foreach (var i in _list)
                {
                    HookValue(i);
                }
            }
        }
Exemplo n.º 2
0
        public ObservableDictionary(IEnumerable <KeyValuePair <TKey, TValue> > values, IEqualityComparer <TKey> keyComparer = null, bool shouldHook = true)
        {
            // 2020-6-17 DWR: We're cloning the input, like we do in ObservableList, rather than accepting a Dictionary reference directly and storing that (that whoever provided it to us could mutate without us being aware here)
            _dictionary = new Dictionary <TKey, TValue>(comparer: keyComparer);
            _shouldHookNestedObservables = shouldHook && PossibleObservableHelpers.IsObservable(typeof(TValue));
            foreach (var entry in values)
            {
                if (_dictionary.ContainsKey(entry.Key))
                {
                    throw new ArgumentException("Key appears multiple times in input data - invalid: " + entry.Key);
                }

                _dictionary.Add(entry.Key, entry.Value);
            }

            // Note: The HookValue method will also check these conditions but we can save ourselve the enumeration if we know that we don't care about hooking nested lists
            if (_shouldHookNestedObservables)
            {
                foreach (var kv in _dictionary)
                {
                    HookValue(kv.Value);
                }
            }
        }