Let's say I have a Dictionary<int,List<Tuple<string,object>>> d
. How could I create with LINQ, from d
, a Dictionary<int,List<Tuple<string,object,AnEnum>>> d'
(where AnEnum
is an enum
) such that each AnEnum
from Tuple<string,object,AnEnum>
is determined by conditions on the <Tuple<string,object>
?
Remark. It's indeed quite a nested structure. Just to explain : in my world there are products that are caracterized by id's ( int
's), and that have fields (named with string
's) whose values are either numeric of string
's -- hence the object
in the Tuple
's. I have an api that to a list of id's List<int>
and a list of fields List<string>
associates a Dictionary<int,List<Tuple<string,object>>>
. According to the values of certains fields, I can know which "type" of product I am dealing with, type that I flag with an enum
.
Umm maybe something like this:
d.ToDictionary(pair => pair.Key,
pair => pair.Value.Select(tuple =>
tuple.Create(tuple.Item1,
tuple.Item2,
ConvertToEnum(tuple))).ToArray());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.