Beispiel #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);
        }
Beispiel #2
0
 public ValueDictionaryIndexed(ValueDictionary items)
 => Items = items;