Say an application has serializer settings with CamelCasePropertyNamesContractResolver and I have a model:
public class Model
{
public int Id { get; set; }
[JsonProperty(Name = "content_text")]
public string Text { get; set; }
}
I'd like to find a way to get the resulting name a serializer would generate on serialize for each property, so that following would be true:
string JsonName<T>(string cSharpPropertyName)
{
//
}
JsonName<Model>(nameof(Model.Id)) == "id";
JsonName<Model>(nameof(Model.Text)) == "content_text";
I'm writing a custom deserializer (JSON converter) for a custom type and I'd like to match my Model properties with JSON input without being case insensitive but with the current serializer strategy.
I had idea to just deserialize each incoming JToken wrapped in a new JSON object to a c# object and check resulting property name but it doesn't seem to be very efficient. Is there a better way to do this?