Use an extension method for subclass detection
This commit is contained in:
parent
3adf91587c
commit
f15d1864c2
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ using System.Linq;
|
|||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using HabitSharp.Extensions;
|
||||
using HabitSharp.Notifications;
|
||||
|
||||
/// <summary>
|
||||
|
@ -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)
|
||||
{
|
||||
|
|
Reference in New Issue