Brad Robinson пре 1 година
родитељ
комит
8e05089a10
6 измењених фајлова са 93 додато и 39 уклоњено
  1. 32 23
      Topten.JsonKit/Emit.cs
  2. 36 0
      Topten.JsonKit/IJsonLoadException.cs
  3. 19 10
      Topten.JsonKit/ReflectionInfo.cs
  4. 4 4
      version.cs
  5. 1 1
      version.json
  6. 1 1
      version.props

+ 32 - 23
Topten.JsonKit/Emit.cs

@@ -673,33 +673,42 @@ namespace Topten.JsonKit
             // Now create the parseInto delegate
             Action<IJsonReader, object> parseInto = (reader, obj) =>
             {
-                // Call IJsonLoading
-                var loading = obj as IJsonLoading;
-                if (loading != null)
-                    loading.OnJsonLoading(reader);
-
-                // Cache IJsonLoadField
-                var lf = obj as IJsonLoadField;
-
-                // Read dictionary keys
-                reader.ParseDictionary(key =>
+                try
                 {
-                    // Call IJsonLoadField
-                    if (lf != null && lf.OnJsonField(reader, key))
-                        return;
+                    // Call IJsonLoading
+                    var loading = obj as IJsonLoading;
+                    if (loading != null)
+                        loading.OnJsonLoading(reader);
 
-                    // Call setters
-                    Action<IJsonReader, object> setter;
-                    if (setters.TryGetValue(key, out setter))
+                    // Cache IJsonLoadField
+                    var lf = obj as IJsonLoadField;
+
+                    // Read dictionary keys
+                    reader.ParseDictionary(key =>
                     {
-                        setter(reader, obj);
-                    }
-                });
+                        // Call IJsonLoadField
+                        if (lf != null && lf.OnJsonField(reader, key))
+                            return;
 
-                // Call IJsonLoaded
-                var loaded = obj as IJsonLoaded;
-                if (loaded != null)
-                    loaded.OnJsonLoaded(reader);
+                        // Call setters
+                        Action<IJsonReader, object> setter;
+                        if (setters.TryGetValue(key, out setter))
+                        {
+                            setter(reader, obj);
+                        }
+                    });
+
+                    // Call IJsonLoaded
+                    var loaded = obj as IJsonLoaded;
+                    if (loaded != null)
+                        loaded.OnJsonLoaded(reader);
+                }
+                catch (Exception x)
+                {
+                    var loadex = obj as IJsonLoadException;
+                    if (loadex != null)
+                        loadex.OnJsonLoadException(reader, x);
+                }
             };
 
             // Since we've created the ParseInto handler, we might as well register

+ 36 - 0
Topten.JsonKit/IJsonLoadException.cs

@@ -0,0 +1,36 @@
+// JsonKit v0.5 - A simple but flexible Json library in a single .cs file.
+// 
+// Copyright (C) 2014 Topten Software (contact@toptensoftware.com) All rights reserved.
+// 
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this product 
+// except in compliance with the License. You may obtain a copy of the License at
+// 
+// http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software distributed under the 
+// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
+// either express or implied. See the License for the specific language governing permissions 
+// and limitations under the License.
+
+
+using System;
+using System.Reflection;
+
+
+namespace Topten.JsonKit
+{
+    /// <summary>
+    /// Optional interface which if implemented on objects serialized will be called after
+    /// the object has been loaded
+    /// </summary>
+    [Obfuscation(Exclude = true, ApplyToMembers = true)]
+    public interface IJsonLoadException
+    {
+        /// <summary>
+        /// Notifies the object that it's been loaded via JSON
+        /// </summary>
+        /// <param name="r">The reader that loaded the object</param>
+        /// <param name="ex">The exception </param>
+        void OnJsonLoadException(IJsonReader r, Exception ex);
+    }
+}

+ 19 - 10
Topten.JsonKit/ReflectionInfo.cs

@@ -107,18 +107,27 @@ namespace Topten.JsonKit
         //     it also works for value types so we use the one method for both
         public void ParseInto(IJsonReader r, object into)
         {
-            var loading = into as IJsonLoading;
-            if (loading != null)
-                loading.OnJsonLoading(r);
-
-            r.ParseDictionary(key =>
+            try
             {
-                ParseFieldOrProperty(r, into, key);
-            });
+                var loading = into as IJsonLoading;
+                if (loading != null)
+                    loading.OnJsonLoading(r);
 
-            var loaded = into as IJsonLoaded;
-            if (loaded != null)
-                loaded.OnJsonLoaded(r);
+                r.ParseDictionary(key =>
+                {
+                    ParseFieldOrProperty(r, into, key);
+                });
+
+                var loaded = into as IJsonLoaded;
+                if (loaded != null)
+                    loaded.OnJsonLoaded(r);
+            }
+            catch (Exception x)
+            {
+                var loadex = into as IJsonLoadException;
+                if (loadex != null)
+                    loadex.OnJsonLoadException(r, x);
+            }
         }
 
         // The member info is stored in a list (as opposed to a dictionary) so that

+ 4 - 4
version.cs

@@ -2,14 +2,14 @@
 // Generated by build tool, do not edit
 using System;
 using System.Reflection;
-[assembly: AssemblyCopyright("Copyright © 2014-2022 Topten Software. All Rights Reserved")]
-[assembly: AssemblyVersion("1.1.139")]
-[assembly: AssemblyFileVersion("1.1.139")]
+[assembly: AssemblyCopyright("Copyright © 2014-2023 Topten Software. All Rights Reserved")]
+[assembly: AssemblyVersion("1.1.140")]
+[assembly: AssemblyFileVersion("1.1.140")]
 [assembly: AssemblyCompany("Topten Software")]
 [assembly: AssemblyProduct("JsonKit")]
 
 static class BuildInfo
 {
-	public static DateTime Date = new DateTime(2022, 7, 29, 2, 3, 34, DateTimeKind.Utc);
+	public static DateTime Date = new DateTime(2023, 3, 19, 5, 5, 23, DateTimeKind.Utc);
 }
 	

+ 1 - 1
version.json

@@ -1,7 +1,7 @@
 {
     "major": 1,
     "minor": 1,
-    "build": 139,
+    "build": 140,
     "copyrightYear": 2014,
     "productName": "JsonKit",
     "companyName": "Topten Software"

+ 1 - 1
version.props

@@ -2,7 +2,7 @@
 <!-- Generated by build tool, do not edit -->
 <Project>
   <PropertyGroup>
-  	<Version Condition="'$(Variable)' == ''">1.1.139</Version>
+  	<Version Condition="'$(Variable)' == ''">1.1.140</Version>
   </PropertyGroup>
 </Project>