diff --git a/README.md b/README.md
index e023be690c6b93123c603601d838800d58dfecf0..d0216928977225873d0855ddea1e2a6f41fe1a1e 100644
--- a/README.md
+++ b/README.md
@@ -16,9 +16,7 @@
**注意:**
-- **从 3.0 后分离了各个功能包,极力避免`DotNetCommon.Core`对其他包的依赖;**
-
-- **从 4.0 后使用`SharpCompress`替代`SharpZipLib` 封装解压缩功能;**
+- **从 4.0 后移除了对`Newtonsoft.Json`的依赖,这样`DotNetCommon.Core`将不依赖任何三方包;**
**整体关系如下图:**
@@ -30,9 +28,7 @@
>
> 1. DotNetCommon包 具有所有功能,引用了其他的各个功能包;
>
-> 2. DotNeCommon.Core 是核心包,在 `https://github.com/NimaAra/Easy.Common`基础上扩充而成;
->
-> 虽然,极力在避免其他的依赖,但还是无法避免对`Newtonsoft.Json`的引用,因为`System.Text.Json`不支持`jsonpath`。
+> 2. DotNeCommon.Core 是核心包,在 `https://github.com/NimaAra/Easy.Common`基础上扩充而成,从DotNetCommon.Core4.0.0开始移除了对Newtonsoft.Json的依赖,之后将不再依赖任何三方包;
>
> 3. DotNetCommon.PinYin 是汉字转拼音包,从`https://github.com/toolgood/ToolGood.Words.Pinyin`搬运;
>
diff --git a/docs/README.md b/docs/README.md
index 72892565cdbb7379c15d5c0a511569bd1fc5cfed..859f897ec3c6eedf1c5f629bae162a12164ac931 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -16,9 +16,7 @@
**注意:**
-- **从 3.0 后分离了各个功能包,极力避免`DotNetCommon.Core`对其他包的依赖;**
-
-- **从 4.0 后使用`SharpCompress`替代`SharpZipLib`封装解压缩功能;**
+- **从 4.0 后移除了对`Newtonsoft.Json`的依赖,这样`DotNetCommon.Core`将不依赖任何三方包;**
**整体关系如下图:**
@@ -30,9 +28,7 @@
>
> 1. DotNetCommon包 具有所有功能,引用了其他的各个功能包;
>
-> 2. DotNeCommon.Core 是核心包,在 `https://github.com/NimaAra/Easy.Common`基础上扩充而成;
->
-> 虽然,极力在避免其他的依赖,但还是无法避免对`Newtonsoft.Json`的引用,因为`System.Text.Json`不支持`jsonpath`。
+> 2. DotNeCommon.Core 是核心包,在 `https://github.com/NimaAra/Easy.Common`基础上扩充而成,从DotNetCommon.Core4.0.0开始移除了对Newtonsoft.Json的依赖,之后将不再依赖任何三方包;
>
> 3. DotNetCommon.PinYin 是汉字转拼音包,从`https://github.com/toolgood/ToolGood.Words.Pinyin`搬运;
>
diff --git a/docs/imgs/image-20221101092958287.png b/docs/imgs/image-20221101092958287.png
index b157cdf4fa746a4c28304be5b43ae98c4afbf695..e96c59fd6ffd94335f139525364b9276db443a94 100644
Binary files a/docs/imgs/image-20221101092958287.png and b/docs/imgs/image-20221101092958287.png differ
diff --git a/src/DotNetCommon.Compress/CompressHelper.cs b/src/DotNetCommon.Compress/CompressHelper.cs
index 05de41ee1d39978006f508ba690b5b65383706e5..ac166cfcbc70c082fe3d839e60136982730cf11f 100644
--- a/src/DotNetCommon.Compress/CompressHelper.cs
+++ b/src/DotNetCommon.Compress/CompressHelper.cs
@@ -224,7 +224,7 @@ namespace DotNetCommon.Compress
}
else if (new[] { ".zip", ".7z" }.Any(i => src.EndsWith(i, StringComparison.OrdinalIgnoreCase)))
{
- var archive = ArchiveFactory.Open(src, GetReaderOptions());
+ using var archive = ArchiveFactory.Open(src, GetReaderOptions());
foreach (var entry in archive.Entries)
{
if (!entry.IsDirectory)
diff --git a/src/DotNetCommon.Core/Data/Page.cs b/src/DotNetCommon.Core/Data/Page.cs
index b73c7a66a25144a590bcc95a386012e51164383d..4b2c2a68e76dc55425f4685d7077202981791a27 100644
--- a/src/DotNetCommon.Core/Data/Page.cs
+++ b/src/DotNetCommon.Core/Data/Page.cs
@@ -1,5 +1,4 @@
-using Newtonsoft.Json;
-using System;
+using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
@@ -9,7 +8,6 @@ namespace DotNetCommon.Data
///
/// 分页数据
///
- [JsonObject(MemberSerialization.OptOut)]
[DataContract]
public class Page
{
diff --git a/src/DotNetCommon.Core/Data/PageQuery.cs b/src/DotNetCommon.Core/Data/PageQuery.cs
index 7ece93ffc926d8701f2b74256fcfbb41de8aaed9..f884d01f24a25ddb5597b8c3324159d302950e50 100644
--- a/src/DotNetCommon.Core/Data/PageQuery.cs
+++ b/src/DotNetCommon.Core/Data/PageQuery.cs
@@ -1,5 +1,4 @@
-using Newtonsoft.Json;
-using System;
+using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
@@ -9,7 +8,6 @@ namespace DotNetCommon.Data
///
/// 分页查询请求
///
- [JsonObject(MemberSerialization.OptOut)]
[DataContract]
public class PageQuery
{
diff --git a/src/DotNetCommon.Core/Data/Result.cs b/src/DotNetCommon.Core/Data/Result.cs
index dd3162a169832655f3b9ac16e2407e282107ab6f..be9979339154d40fa91184a891b59bea1ef54fa6 100644
--- a/src/DotNetCommon.Core/Data/Result.cs
+++ b/src/DotNetCommon.Core/Data/Result.cs
@@ -1,8 +1,8 @@
-using Newtonsoft.Json;
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
+using System.Text.Json;
using System.Threading.Tasks;
using DotNetCommon.Extensions;
@@ -11,7 +11,6 @@ namespace DotNetCommon.Data
///
/// 通用结果模型
///
- [JsonObject(MemberSerialization.OptOut)]
[DataContract]
public class Result
{
@@ -123,7 +122,7 @@ namespace DotNetCommon.Data
if (data == null) this.Data = default(T);
else
{
- this.Data = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(data));
+ this.Data = JsonSerializer.Deserialize(JsonSerializer.Serialize(data));
}
}
return this;
@@ -308,8 +307,8 @@ namespace DotNetCommon.Data
Success = true,
Data = t
};
- var json = Newtonsoft.Json.JsonConvert.SerializeObject(value);
- t = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
+ var json = System.Text.Json.JsonSerializer.Serialize(value);
+ t = System.Text.Json.JsonSerializer.Deserialize(json);
return new Result()
{
Success = true,
diff --git a/src/DotNetCommon.Core/Data/ResultPage.cs b/src/DotNetCommon.Core/Data/ResultPage.cs
index c8638937478511e6dbd9e52b7a6f7abd2a2fca6d..a2f794ce2c81d272da55d904147560d2dc54156a 100644
--- a/src/DotNetCommon.Core/Data/ResultPage.cs
+++ b/src/DotNetCommon.Core/Data/ResultPage.cs
@@ -1,5 +1,4 @@
-using Newtonsoft.Json;
-using System;
+using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
@@ -9,7 +8,6 @@ namespace DotNetCommon.Data
///
/// 返回分页结果数据
///
- [JsonObject(MemberSerialization.OptOut)]
[DataContract]
public class ResultPage : Result>
{
diff --git a/src/DotNetCommon.Core/Data/TreeNode.cs b/src/DotNetCommon.Core/Data/TreeNode.cs
index 46b588008b509fb2e0f75fcf4a641d41eacdfa95..f6070f17212c3cbfa4108f358008acdf87b10db1 100644
--- a/src/DotNetCommon.Core/Data/TreeNode.cs
+++ b/src/DotNetCommon.Core/Data/TreeNode.cs
@@ -1,5 +1,4 @@
-using Newtonsoft.Json;
-using System;
+using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
@@ -10,7 +9,6 @@ namespace DotNetCommon.Data
/// 树节点模型
///
/// 模型数据
- [JsonObject(MemberSerialization.OptOut)]
[DataContract]
public sealed class TreeNode
{
diff --git a/src/DotNetCommon.Core/DeepCloneHelper.cs b/src/DotNetCommon.Core/DeepCloneHelper.cs
index 773eb804a76f72e622721611d9511635fcec41ee..fb869b200947c6f59e7237437345b782d4cc5015 100644
--- a/src/DotNetCommon.Core/DeepCloneHelper.cs
+++ b/src/DotNetCommon.Core/DeepCloneHelper.cs
@@ -1,6 +1,5 @@
using DotNetCommon.Data;
using DotNetCommon.Extensions;
-using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Concurrent;
@@ -10,6 +9,9 @@ using System.Linq.Expressions;
using System.Numerics;
using System.Reflection;
using System.Text;
+using System.Text.Json;
+using System.Text.Json.Nodes;
+using System.Text.Json.Serialization;
namespace DotNetCommon
{
@@ -184,19 +186,51 @@ namespace DotNetCommon
}
else if (reflect.Name == "Newtonsoft.Json.Linq.JObject")
{
- wrapper.Method = (obj, dic) => dic.ContainsKey(obj) ? dic.get_Item(obj) : (obj as JObject).DeepClone();
+ var tmp = type.Assembly.GetType("Newtonsoft.Json.Linq.JObject");
+ var tmp2 = tmp.GetMethod("DeepClone");
+ var tmp3 = Expression.Parameter(typeof(object), "obj");
+ var act = Expression.Lambda>(Expression.Call(Expression.TypeAs(tmp3, tmp), tmp2), tmp3).Compile();
+ wrapper.Method = (obj, dic) => dic.ContainsKey(obj) ? dic.get_Item(obj) : act(obj);
return wrapper;
}
else if (reflect.Name == "Newtonsoft.Json.Linq.JArray")
{
- wrapper.Method = (obj, dic) => dic.ContainsKey(obj) ? dic.get_Item(obj) : (obj as JArray).DeepClone();
+ var tmp = type.Assembly.GetType("Newtonsoft.Json.Linq.JArray");
+ var tmp2 = tmp.GetMethod("DeepClone");
+ var tmp3 = Expression.Parameter(typeof(object), "obj");
+ var act = Expression.Lambda>(Expression.Call(Expression.TypeAs(tmp3, tmp), tmp2), tmp3).Compile();
+ wrapper.Method = (obj, dic) => dic.ContainsKey(obj) ? dic.get_Item(obj) : act(obj);
return wrapper;
}
else if (reflect.Name == "Newtonsoft.Json.Linq.JToken")
{
- wrapper.Method = (obj, dic) => dic.ContainsKey(obj) ? dic.get_Item(obj) : (obj as JToken).DeepClone();
+ var tmp = type.Assembly.GetType("Newtonsoft.Json.Linq.JToken");
+ var tmp2 = tmp.GetMethod("DeepClone");
+ var tmp3 = Expression.Parameter(typeof(object), "obj");
+ var act = Expression.Lambda>(Expression.Call(Expression.TypeAs(tmp3, tmp), tmp2), tmp3).Compile();
+ wrapper.Method = (obj, dic) => dic.ContainsKey(obj) ? dic.get_Item(obj) : act(obj);
return wrapper;
}
+ #region TODO JsonObject/JsonArray/JsonDocument 原生没有提供clone方法
+ else if (reflect.Name == "System.Text.Json.Nodes.JsonObject")
+ {
+ Func