I have the below code in my method (actually an async static Task)
try
{
string responseValues = JSONtoKeyValue(responseBody);
Console.WriteLine("responseValues = " + responseValues);
//var dict = responseValues.Split('|').Select(x => x.Split('=')).ToDictionary(x => x[0], x => x[1]);
var dict = responseValues.Split('|')
.Select(x => x.Split('='))
.Where(x => x.Length > 1 && !String.IsNullOrEmpty(x[0].Trim())
&& !String.IsNullOrEmpty(x[1].Trim()))
.ToDictionary(x => x[0].Trim(), x => x[1].Trim());
Console.WriteLine("Dictionary created.");
Console.ReadLine();
foreach (KeyValuePair<string, string> entry in dict)
{
if (entry.Value == null)
{
dict.Remove(entry.Key);
}
else
{
string key = entry.Key;
string value = entry.Value;
if (cnsnt.GetType().GetTypeInfo().GetDeclaredProperty(key) != null)
{
cnsnt.GetType().GetTypeInfo().GetDeclaredProperty(key).SetValue(value);
}
}
}
}
catch (System.Exception e)
{
Console.WriteLine(e.Message);
}
My problem is two-fold. First, I can't handle the duplicates for the dictionary (wanted to just keep the latest value if the key already exists) but even when I try with no duplicates, when I try to see if I have the property that the key has, I get error No overload for method SetValue has only one argument.
Any help would be appreciated immensely ..