Forráskód Böngészése

small utility class to check extras

Vicente Penades 6 éve
szülő
commit
a8a131904e
2 módosított fájl, 41 hozzáadás és 3 törlés
  1. 41 0
      src/SharpGLTF.Core/IO/Json.cs
  2. 0 3
      src/SharpGLTF.Core/IO/Unknown.cs

+ 41 - 0
src/SharpGLTF.Core/IO/Json.cs

@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace SharpGLTF.IO
+{
+    static class JsonUtils
+    {
+        public static bool IsSerializable(Object value)
+        {
+            if (value == null) return false;
+
+            if (value is IConvertible cvt)
+            {
+                var t = cvt.GetTypeCode();
+                if (t == TypeCode.Empty) return false;
+                if (t == TypeCode.DBNull) return false;
+                if (t == TypeCode.Object) return false;
+                if (t == TypeCode.DateTime) return false;
+                return true;
+            }
+
+            if (value is JsonList list)
+            {
+                return list.All(item => IsSerializable(item));
+            }
+
+            if (value is JsonDictionary dict)
+            {
+                return dict.Values.All(item => IsSerializable(item));
+            }
+
+            return false;
+        }
+    }
+
+    public class JsonList : List<Object> { }
+
+    public class JsonDictionary : Dictionary<String, Object> { }
+}

+ 0 - 3
src/SharpGLTF.Core/IO/Unknown.cs

@@ -6,9 +6,6 @@ using Newtonsoft.Json;
 
 
 namespace SharpGLTF.IO
 namespace SharpGLTF.IO
 {
 {
-    public class JsonDictionary : Dictionary<String, Object> { }
-
-    public class JsonList : List<Object> { }
 
 
     [System.Diagnostics.DebuggerDisplay("Unknown {_Name}")]
     [System.Diagnostics.DebuggerDisplay("Unknown {_Name}")]
     class UnknownNode : JsonSerializable
     class UnknownNode : JsonSerializable