Explorar o código

SsError.errorDetail 由JObject改为Object类型

lith %!s(int64=4) %!d(string=hai) anos
pai
achega
b17bc9226e

+ 3 - 2
dotnet/Library/Vit/Vit.Core/Test/Vit.Core.MsTest/Util/ComponentModel/ExceptionTest.cs

@@ -1,4 +1,5 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Newtonsoft.Json.Linq;
 using Vit.Core.Util.ComponentModel.SsError;
 using Vit.Extensions;
 
@@ -20,13 +21,13 @@ namespace Vit.Core.MsTest.Util.ComponentModel
             try
             {
 
-                throw new System.Exception().ErrorCode_Set(ErrorCode).ErrorMessage_Set(ErrorMessage).ErrorDetail_Set(nameof(ErrorDetail_Opt), ErrorDetail_Opt);
+                throw new System.Exception().ErrorCode_Set(ErrorCode).ErrorMessage_Set(ErrorMessage).ErrorDetail_Set(new {  ErrorDetail_Opt });
             }
             catch (System.Exception ex)
             {
                 Assert.AreEqual(ErrorCode, ex.ErrorCode_Get());
                 Assert.AreEqual(ErrorMessage, ex.ErrorMessage_Get());
-                Assert.AreEqual(ErrorDetail_Opt, ex.ErrorDetail_Get(nameof(ErrorDetail_Opt)));
+                Assert.AreEqual(ErrorDetail_Opt, ex.ErrorDetail_Get<JObject>()[nameof(ErrorDetail_Opt)]);
 
             }
 

+ 8 - 30
dotnet/Library/Vit/Vit.Core/Vit.Core/Util/ComponentModel/SsError/Extensions/ExceptionExtensions.cs

@@ -41,7 +41,7 @@ namespace Vit.Extensions
             {
                 throw new ArgumentNullException(nameof(ex));
             }
-            return (ex.Data[key]).Convert<Type>() ;
+            return (ex.Data[key]).ConvertBySerialize<Type>() ;
         }
         #endregion
 
@@ -130,7 +130,7 @@ namespace Vit.Extensions
         /// <param name="ex"></param>
         /// <param name="ErrorDetail"></param>
         [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
-        public static Exception ErrorDetail_Set(this Exception ex, JObject ErrorDetail)
+        public static Exception ErrorDetail_Set<Type>(this Exception ex, Type ErrorDetail)
         {
             ex.Data_Set("ErrorDetail", ErrorDetail);
             return ex;
@@ -141,44 +141,22 @@ namespace Vit.Extensions
         /// <param name="ex"></param>
         /// <returns></returns>
         [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
-        public static JObject ErrorDetail_Get(this Exception ex)
+        public static Type ErrorDetail_Get<Type>(this Exception ex)
         {
-            return ex.Data_Get<JObject>("ErrorDetail");
+            return ex.Data_Get<Type>("ErrorDetail");
         }
-        #endregion
 
-        #region ErrorDetail
         /// <summary>
-        /// SsError。设置ErrorDetail的属性值。若ErrorDetail为null,则会自动创建
-        /// </summary>
-        /// <param name="ex"></param>
-        /// <param name="key"></param>
-        /// <param name="value"></param>
-        [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
-        public static Exception ErrorDetail_Set(this Exception ex, string key,object value)
-        {
-            var ErrorDetail = ex.ErrorDetail_Get();
-            if (null == ErrorDetail)
-            {
-                ex.ErrorDetail_Set(ErrorDetail = new JObject());
-            }
-            ErrorDetail[key] = value.ToJToken();
-            return ex;
-
-        }
-
-        /// <summary>
-        /// SsError。获取ErrorDetail的属性值
+        /// SsError。获取ErrorDetail,可能为null
         /// </summary>
         /// <param name="ex"></param>
-        /// <param name="key"></param>
         /// <returns></returns>
         [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
-        public static object ErrorDetail_Get(this Exception ex, string key)
+        public static object ErrorDetail_Get(this Exception ex)
         {
-            return ex.ErrorDetail_Get()?[key]?.GetValue();
+            return ex.ErrorDetail_Get<object>();
         }
-        #endregion
+        #endregion     
 
 
 

+ 1 - 1
dotnet/Library/Vit/Vit.Core/Vit.Core/Util/ComponentModel/SsError/SsError.cs

@@ -66,7 +66,7 @@ namespace Vit.Core.Util.ComponentModel.SsError
         [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
         [SsExample("{}")]
         [SsDescription("错误详情(json类型)")]
-        public JObject errorDetail { get; set; }
+        public object errorDetail { get; set; }
 
 
 

+ 1 - 1
dotnet/Library/Vit/Vit.Core/Vit.Core/Util/ComponentModel/SsError/SsException.cs

@@ -73,7 +73,7 @@ namespace Vit.Core.Util.ComponentModel.SsError
 
         #region ErrorDetail
 
-        public JObject ErrorDetail
+        public object ErrorDetail
         {
             get
             {