I have a class like following:
public class Client {
[JsonProperty("first_name")]
public string FirstName { get; set; }
[JsonProperty("last_name")]
public string LastName { get; set; }
}
using the following code I can get the properties and values in a dictionary of that class object:
var propertyValuesByName = client.GetType().GetProperties()
.Where(pi => pi.PropertyType == typeof(string))
.Select(pi => new { Val = (string) pi.GetValue(client), Name = pi.Name })
.ToDictionary(pi => pi.Name, pi => pi.Val);
so the dictionary contains property name as key and the property value as value. But what I want is, get the dictionary which key will be the object JsonProperty name instead of the real property name, means instead of "FirstName" I want "first_name" as key. How can I modify the above code to achieve this?