Пример #1
0
        public ValueDictionary Add(ValueDictionary item)
        {
            if (item == null)
            {
                var col = new ValueDictionary(this);
                col.RemoveCollection(i => i.Value?.Option == ValueOption.Exclude);
                return(col);
            }

            var newCollection = new ValueDictionary(this.Where(i => i.Value?.Option == ValueOption.Include).ToDictionary(k => k.Key, k => k.Value));

            if (!item.Any())
            {
                return(newCollection);
            }

            foreach (var key in item.Keys)
            {
                var value = item[key];
                if (value == null)
                {
                    continue;
                }

                if (newCollection.TryGetValue(key, out var existingValue))
                {
                    newCollection.Remove(key);
                    if (value.Option == ValueOption.Include)
                    {
                        newCollection.Add(key, value);
                    }
                }
                else
                {
                    newCollection.Add(key, value);
                }
            }
            return(newCollection);
        }
Пример #2
0
 public ValueDictionaryIndexed(ValueDictionary items)
 => Items = items;