lucidiot/HabitSharp
lucidiot
/
HabitSharp
Archived
1
0
Fork 0

Use an extension method for subclass detection

This commit is contained in:
Lucidiot 2018-11-10 18:46:10 +01:00
parent 3adf91587c
commit f15d1864c2
No known key found for this signature in database
GPG Key ID: AE3F7205692FA205
2 changed files with 11 additions and 1 deletions

View File

@ -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);
}
}
}

View File

@ -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)
{