I have this kind of data type:
Dictionary<string, List<Dictionary<string, List<Dictionary<string, List<Dictionary<string, string>>>>>>>
and whenever I'm trying to reach the very bottom parts of it to count some stuff there I'm having an error that I can't use foreach on KeyValuePairs:
foreach statement cannot operate on variables of type 'KeyValuePair<string, List<Dictionary<string, List<Dictionary<string, string>>>>>' because 'KeyValuePair<string, List<Dictionary<string, List<Dictionary<string, string>>>>>' does not contain a public definition for 'GetEnumerator' [RestService]
Here's that part of loops:
void GetMetricsCount(List<Dictionary<string, List<Dictionary<string, List<Dictionary<string, string>>>>>> device, Dictionary<string, string> results_holder)
{
// count all metrics
foreach (var type_element in device)
{
foreach (var group_element in type_element)
{
foreach (var wtf in group_element)
Now it would be actually really good if there is any better way to deal with that kind of complicated data structures in C# and I would really appreciate if anyone tells me how because this is yuck!
UPDATE: I'm sorry for it but I've cut some code above while copying it here. Here's the answer to frustrations with non-matching types:
// Get overview of metrics for last 24h
public Dictionary<string, Dictionary<string, string>> GetMetricsOverview()
{
var overview_results = new Dictionary<string, Dictionary<string, string>>();
// get total item count for each metric group and add to holder
void GetMetricsCount(List<Dictionary<string, List<Dictionary<string, List<Dictionary<string, string>>>>>> device, Dictionary<string, string> results_holder)
{
// count all metrics
foreach (var type_element in device)
{
foreach (var group_element in type_element.Values)
{
foreach (var wtf in group_element)
results_holder.Add(group_element.Key + "_count", group_element.Value.Count.ToString());
}
}
//
}
//