I have a Dictionary<string, Dictionary<string, object>> that needs to be sorted depending on a certain value of the child dictionary.
e.g
{
"James": {
"Age": 21,
"Surname": "Doe",
"Temp": 80.6
},
"Tobi": {
"Age": 26,
"Surname": "Doe",
"Temp": 60.5
}
}
The dictionary with key James and Tobi needs to be sorted depending on i.e. the temp value. The string "Temp" would be given to the method to indicate the key to be sorted on.
The object values type would differ depending on the context but the type would be known to the method allowing to cats the object to the correct type for comparison.
Creating a specific object would not be possible for the solution as dictionary<string, object> represents the object properties and would differ with each implementation of the method.
All child dictionaries would have the same "properties" so the child dictionary not having the value would not be a problem.
so in plain description, a method taking in:
{
"James": {
"Age": 21,
"Surname": "Doe",
"Temp": 80.6
},
"Tobi": {
"Age": 26,
"Surname": "Doe",
"Temp": 60.5
},
"Jessica": {
"Age": 18,
"Surname": "Samms",
"Temp": 50.67
}
}
and
string "Temp"
and posibily Temp type of
string "double"
that returns
IEnumerable<KeyValuePair<string,Dictionary<string,object>>>
{
"Jessica": {
"Age": 18,
"Surname": "Samms",
"Temp": 50.67
},
"Tobi": {
"Age": 26,
"Surname": "Doe",
"Temp": 60.5
},
"James": {
"Age": 21,
"Surname": "Doe",
"Temp": 80.6
}
}
Dictionary<string, Dictionary<string, object>>but rather aDictionary<string, T>. Take a look at my sample: dotnetfiddle.net/J8DgS5