I have a dictionary of the type:
IDictionary> my_dictionary
bar class looks like this:
cl
Something like this?
my_dictionary
.Where(p=> p.Value.Any(x => x.IsValid))
.ToDictionary( p=> p.Key,
p=> p.Value.Where (x => x.IsValid));
That will only include items where at least one of the values IsValid
.
my_dictionary.Where(p => p.Any(v => v.Value.IsValid())
.ToDictionary(p=> p.Key,
p=> p.Value.Where(x => x.Value.IsValid());
Get Only the Items that have a true in the Value, then only get the items that are true into the new dictonary.
Filter then create the dictonary
var new_dict = my_dictionary.Select(x => new KeyValuePair<foo, List<bar>>(
x.Key,
x.Value
.Where(y => y.IsValid)
.ToList()))
.Where(x => x.Value.Count > 0)
.ToDictionary(x => x.Key, x => x.Value.AsReadOnly());