From cf46c2d5503317db0edf4c51d0b5fc5139b26242 Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 19 Mar 2023 01:58:18 +0000 Subject: [PATCH] simplified JsonPathConverter --- WeatherDashboard/JsonPathConverter.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/WeatherDashboard/JsonPathConverter.cs b/WeatherDashboard/JsonPathConverter.cs index 2a466df..38de54c 100644 --- a/WeatherDashboard/JsonPathConverter.cs +++ b/WeatherDashboard/JsonPathConverter.cs @@ -13,12 +13,9 @@ namespace WeatherDashboard foreach (PropertyInfo prop in objectType.GetProperties().Where(p => p.CanRead && p.CanWrite)) { - var attribute = prop - .GetCustomAttributes(true) - .OfType() - .FirstOrDefault(); - - var jsonPath = (attribute != null ? attribute.PropertyName : prop.Name); + var attribute = prop.GetCustomAttribute(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(); } -} +} \ No newline at end of file