I would like to convert all class property names and values to a Dictionary<string, string>. However instead of using the regular property names I would like the JsonPropertyNames i.e.
dictionary.Add(item.JsonPropertyName, item.Value)
Something like the answer but modified to get the JsonPropertyNames. Getting these attributes in a loop similar to below is proving more difficult than expected.
https://stackoverflow.com/a/9210587/4280872
Location local = new Location();
local.city = "Lisbon";
local.country = "Portugal";
local.state = "None";
PropertyInfo[] infos = local.GetType().GetProperties();
Dictionary<string,string> dix = new Dictionary<string,string> ();
foreach (PropertyInfo info in infos)
{
dix.Add(info.Name, info.GetValue(local, null).ToString());
}
foreach (string key in dix.Keys)
{
Console.WriteLine("nameProperty: {0}; value: {1}", key, dix[key]);
}
Console.Read();