mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
Revert "Json扩展支持JsonSerializerSettings"
This reverts commit d8f49808a8
.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45;net40;netcoreapp3.0</TargetFrameworks>
|
||||
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
|
||||
<Version>1.3.0-preview10</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
@ -24,16 +24,13 @@
|
||||
<ItemGroup>
|
||||
<None Include="../../logo.png" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
|
||||
<DocumentationFile>FreeSql.Extensions.JsonMap.xml</DocumentationFile>
|
||||
<WarningLevel>3</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">
|
||||
<DefineConstants>NETCORE30</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp3.0' ">
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -6,9 +6,7 @@ using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
#if NETCORE30
|
||||
using System.Text.Json;
|
||||
#endif
|
||||
|
||||
namespace FreeSql.Extensions
|
||||
{
|
||||
public static class JsonMapCore
|
||||
@ -16,38 +14,23 @@ namespace FreeSql.Extensions
|
||||
static bool _isAoped = false;
|
||||
static object _isAopedLock = new object();
|
||||
static ConcurrentDictionary<Type, bool> _dicTypes = new ConcurrentDictionary<Type, bool>();
|
||||
#if NETCORE30
|
||||
static MethodInfo MethodJsonConvertDeserializeObject = typeof(JsonSerializer).GetMethod(nameof(JsonSerializer.Deserialize), new[] { typeof(string), typeof(Type) });
|
||||
static MethodInfo MethodJsonConvertDeserializeObject = typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) });
|
||||
static MethodInfo MethodJsonConvertSerializeObject = typeof(JsonConvert).GetMethod("SerializeObject", new[] { typeof(object) });
|
||||
|
||||
static MethodInfo MethodJsonConvertSerializeObject = typeof(JsonSerializer).GetMethod(nameof(JsonSerializer.Serialize), new[] { typeof(object), typeof(Type), typeof(JsonSerializerOptions) });
|
||||
#else
|
||||
static MethodInfo MethodJsonConvertDeserializeObject = typeof(JsonConvert).GetMethod(nameof(JsonConvert.DeserializeObject), new[] { typeof(string), typeof(Type) });
|
||||
|
||||
static MethodInfo MethodJsonConvertSerializeObject = typeof(JsonConvert).GetMethod(nameof(JsonConvert.SerializeObject), new[] { typeof(object), typeof(JsonSerializerSettings) });
|
||||
#endif
|
||||
/// <summary>
|
||||
/// 当实体类属性为【对象】时,并且标记特性 [JsonMap] 时,该属性将以JSON形式映射存储
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
public static void UseJsonMap(this IFreeSql that)
|
||||
{
|
||||
UseJsonMap(that,
|
||||
#if NETCORE30
|
||||
new JsonSerializerOptions()
|
||||
UseJsonMap(that,new JsonSerializerSettings());
|
||||
}
|
||||
|
||||
#else
|
||||
new JsonSerializerSettings()
|
||||
#endif
|
||||
);}
|
||||
#if NETCORE30
|
||||
public static void UseJsonMap(this IFreeSql that, JsonSerializerOptions settings)
|
||||
#else
|
||||
public static void UseJsonMap(this IFreeSql that, JsonSerializerSettings settings)
|
||||
#endif
|
||||
|
||||
{
|
||||
if (_isAoped == false)
|
||||
lock (_isAopedLock)
|
||||
lock(_isAopedLock)
|
||||
if (_isAoped == false)
|
||||
{
|
||||
_isAoped = true;
|
||||
@ -69,13 +52,7 @@ namespace FreeSql.Extensions
|
||||
{
|
||||
return Expression.IfThenElse(
|
||||
Expression.TypeEqual(valueExp, e.Property.PropertyType),
|
||||
Expression.Return(returnTarget, Expression.Call(MethodJsonConvertSerializeObject,
|
||||
#if NETCORE30
|
||||
Expression.Convert(valueExp, typeof(object)), Expression.Constant(valueExp.Type), Expression.Constant(settings))
|
||||
#else
|
||||
Expression.Convert(valueExp, typeof(object)), Expression.Constant(settings))
|
||||
#endif
|
||||
, typeof(object)),
|
||||
Expression.Return(returnTarget, Expression.Call(MethodJsonConvertSerializeObject, Expression.Convert(valueExp, typeof(object)), Expression.Constant(settings)), typeof(object)),
|
||||
elseExp);
|
||||
});
|
||||
}
|
||||
@ -83,6 +60,5 @@ namespace FreeSql.Extensions
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user