瀏覽代碼

CORE - Serialization fix for type.IsSubClassOf error

Nick-PRSDigital@bitbucket.org 2 年之前
父節點
當前提交
9932cbce17
共有 1 個文件被更改,包括 4 次插入4 次删除
  1. 4 4
      InABox.Core/Serialization.cs

+ 4 - 4
InABox.Core/Serialization.cs

@@ -653,7 +653,7 @@ namespace InABox.Core
         public static void WriteObject<TObject>(this CoreBinaryWriter writer, TObject entity, Type type)
             where TObject : BaseObject
         {
-            if (!type.IsSubclassOf(typeof(TObject)))
+            if (!type.IsAssignableFrom(typeof(TObject)))
                 throw new Exception($"{type.EntityName()} is not a subclass of {typeof(TObject).EntityName()}");
 
             var properties = SerializableProperties(type).ToList();
@@ -682,7 +682,7 @@ namespace InABox.Core
         public static TObject ReadObject<TObject>(this CoreBinaryReader reader, Type type)
             where TObject : BaseObject
         {
-            if (!type.IsSubclassOf(typeof(TObject)))
+            if (!type.IsAssignableFrom(typeof(TObject)))
                 throw new Exception($"{type.EntityName()} is not a subclass of {typeof(TObject).EntityName()}");
 
             var obj = (Activator.CreateInstance(type) as TObject)!;
@@ -727,7 +727,7 @@ namespace InABox.Core
         public static void WriteObjects<TObject>(this CoreBinaryWriter writer, Type type, ICollection<TObject>? objects)
             where TObject : BaseObject
         {
-            if (!type.IsSubclassOf(typeof(TObject)))
+            if (!type.IsAssignableFrom(typeof(TObject)))
                 throw new Exception($"{type.EntityName()} is not a subclass of {typeof(TObject).EntityName()}");
 
             var nObjs = objects?.Count ?? 0;
@@ -769,7 +769,7 @@ namespace InABox.Core
         
         public static List<TObject> ReadObjects<TObject>(this CoreBinaryReader reader, Type type) where TObject : BaseObject
         {
-            if (!type.IsSubclassOf(typeof(TObject)))
+            if (!type.IsAssignableFrom(typeof(TObject)))
                 throw new Exception($"{type.EntityName()} is not a subclass of {typeof(TObject).EntityName()}");
             
             var objs = new List<TObject>();