diff --git a/Extensions/TypeExtensions.cs b/Extensions/TypeExtensions.cs new file mode 100644 index 0000000..5967cb9 --- /dev/null +++ b/Extensions/TypeExtensions.cs @@ -0,0 +1,9 @@ +using System; + +namespace HabitSharp.Extensions { + public static class TypeExtensions { + public static bool IsOrSubclass(this Type type, Type baseType) { + return type == baseType || type.IsSubclassOf(baseType); + } + } +} diff --git a/Serialization/NotificationConverter.cs b/Serialization/NotificationConverter.cs index 8234a50..3e3217f 100644 --- a/Serialization/NotificationConverter.cs +++ b/Serialization/NotificationConverter.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Collections.Generic; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using HabitSharp.Extensions; using HabitSharp.Notifications; /// @@ -29,7 +30,7 @@ public class NotificationConverter : JsonConverter ) ?? typeof(Notification); // Default to the Notification class } - public override bool CanConvert(Type objectType) => objectType.IsSubclassOf(typeof(Notification)) || objectType == typeof(Notification); + public override bool CanConvert(Type objectType) => objectType.IsOrSubclass(typeof(Notification)); public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {