simplified JsonPathConverter
This commit is contained in:
parent
9add92c170
commit
cf46c2d550
@ -13,12 +13,9 @@ namespace WeatherDashboard
|
||||
|
||||
foreach (PropertyInfo prop in objectType.GetProperties().Where(p => p.CanRead && p.CanWrite))
|
||||
{
|
||||
var attribute = prop
|
||||
.GetCustomAttributes(true)
|
||||
.OfType<JsonPropertyAttribute>()
|
||||
.FirstOrDefault();
|
||||
|
||||
var jsonPath = (attribute != null ? attribute.PropertyName : prop.Name);
|
||||
var attribute = prop.GetCustomAttribute<JsonPropertyAttribute>(true);
|
||||
|
||||
var jsonPath = attribute != null ? attribute.PropertyName : prop.Name;
|
||||
var token = jsonObject.SelectToken(jsonPath);
|
||||
|
||||
if (token != null && token.Type != JTokenType.Null)
|
||||
@ -30,6 +27,7 @@ namespace WeatherDashboard
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
// CanConvert is not called when [JsonConverter] attribute is used
|
||||
public override bool CanConvert(Type objectType) => false;
|
||||
|
||||
@ -37,4 +35,4 @@ namespace WeatherDashboard
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user