Revert "Json扩展支持JsonSerializerSettings"

This reverts commit d8f49808a831648fac77efb69ebda18cb4ca7bc1.
This commit is contained in:
Eternity 2020-03-21 19:05:30 +08:00
parent d8f49808a8
commit 519f82b046
4 changed files with 19 additions and 52 deletions

View File

@ -18,8 +18,6 @@ namespace base_entity
{ {
public int clicks { get; set; } public int clicks { get; set; }
public string title { get; set; } public string title { get; set; }
public string nullvalue { get; set; }
} }
[Table(Name = "sysconfig")] [Table(Name = "sysconfig")]
public class S_SysConfig<T> : BaseEntity<S_SysConfig<T>> public class S_SysConfig<T> : BaseEntity<S_SysConfig<T>>
@ -45,7 +43,7 @@ namespace base_entity
.UseNoneCommandParameter(true) .UseNoneCommandParameter(true)
.UseConnectionString(FreeSql.DataType.Sqlite, "data source=test.db;max pool size=5") .UseConnectionString(FreeSql.DataType.Sqlite, "data source=test.db;max pool size=5")
//.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=2") //.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=2")
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3") .UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3")
.UseLazyLoading(true) .UseLazyLoading(true)
.Build(); .Build();
BaseEntity.Initialization(fsql); BaseEntity.Initialization(fsql);
@ -61,12 +59,10 @@ namespace base_entity
var items1 = Products.Select.Limit(10).OrderByDescending(a => a.CreateTime).ToList(); var items1 = Products.Select.Limit(10).OrderByDescending(a => a.CreateTime).ToList();
var items2 = fsql.Select<Products>().Limit(10).OrderByDescending(a => a.CreateTime).ToList(); var items2 = fsql.Select<Products>().Limit(10).OrderByDescending(a => a.CreateTime).ToList();
#if NETCORE30
BaseEntity.Orm.UseJsonMap(new System.Text.Json.JsonSerializerOptions { IgnoreNullValues = true }); BaseEntity.Orm.UseJsonMap();
#else
BaseEntity.Orm.UseJsonMap(new JsonSerializerSettings { NullValueHandling=NullValueHandling.Ignore }); new S_SysConfig<TestConfig> { Name = "testkey11", Config = new TestConfig { clicks = 11, title = "testtitle11" } }.Save();
#endif
new S_SysConfig<TestConfig> { Name = "testkey11", Config = new TestConfig { clicks = 11, title = "testtitle11", nullvalue = null } }.Save();
new S_SysConfig<TestConfig> { Name = "testkey22", Config = new TestConfig { clicks = 22, title = "testtitle22" } }.Save(); new S_SysConfig<TestConfig> { Name = "testkey22", Config = new TestConfig { clicks = 22, title = "testtitle22" } }.Save();
new S_SysConfig<TestConfig> { Name = "testkey33", Config = new TestConfig { clicks = 33, title = "testtitle33" } }.Save(); new S_SysConfig<TestConfig> { Name = "testkey33", Config = new TestConfig { clicks = 33, title = "testtitle33" } }.Save();
var testconfigs11 = S_SysConfig<TestConfig>.Select.ToList(); var testconfigs11 = S_SysConfig<TestConfig>.Select.ToList();

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0</TargetFrameworks> <TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@ -13,9 +13,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup> </ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">
<DefineConstants>NETCORE30</DefineConstants>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.BaseEntity\FreeSql.Extensions.BaseEntity.csproj" /> <ProjectReference Include="..\..\Extensions\FreeSql.Extensions.BaseEntity\FreeSql.Extensions.BaseEntity.csproj" />
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.JsonMap\FreeSql.Extensions.JsonMap.csproj" /> <ProjectReference Include="..\..\Extensions\FreeSql.Extensions.JsonMap\FreeSql.Extensions.JsonMap.csproj" />

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45;net40;netcoreapp3.0</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
<Version>1.3.0-preview10</Version> <Version>1.3.0-preview10</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
@ -29,11 +29,8 @@
<DocumentationFile>FreeSql.Extensions.JsonMap.xml</DocumentationFile> <DocumentationFile>FreeSql.Extensions.JsonMap.xml</DocumentationFile>
<WarningLevel>3</WarningLevel> <WarningLevel>3</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">
<DefineConstants>NETCORE30</DefineConstants>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp3.0' "> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup> </ItemGroup>

View File

@ -6,9 +6,7 @@ using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
#if NETCORE30
using System.Text.Json;
#endif
namespace FreeSql.Extensions namespace FreeSql.Extensions
{ {
public static class JsonMapCore public static class JsonMapCore
@ -16,35 +14,20 @@ namespace FreeSql.Extensions
static bool _isAoped = false; static bool _isAoped = false;
static object _isAopedLock = new object(); static object _isAopedLock = new object();
static ConcurrentDictionary<Type, bool> _dicTypes = new ConcurrentDictionary<Type, bool>(); static ConcurrentDictionary<Type, bool> _dicTypes = new ConcurrentDictionary<Type, bool>();
#if NETCORE30 static MethodInfo MethodJsonConvertDeserializeObject = typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) });
static MethodInfo MethodJsonConvertDeserializeObject = typeof(JsonSerializer).GetMethod(nameof(JsonSerializer.Deserialize), 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> /// <summary>
/// 当实体类属性为【对象】时,并且标记特性 [JsonMap] 时该属性将以JSON形式映射存储 /// 当实体类属性为【对象】时,并且标记特性 [JsonMap] 时该属性将以JSON形式映射存储
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static void UseJsonMap(this IFreeSql that) public static void UseJsonMap(this IFreeSql that)
{ {
UseJsonMap(that, UseJsonMap(that,new JsonSerializerSettings());
#if NETCORE30 }
new JsonSerializerOptions()
#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) public static void UseJsonMap(this IFreeSql that, JsonSerializerSettings settings)
#endif
{ {
if (_isAoped == false) if (_isAoped == false)
lock(_isAopedLock) lock(_isAopedLock)
@ -69,13 +52,7 @@ namespace FreeSql.Extensions
{ {
return Expression.IfThenElse( return Expression.IfThenElse(
Expression.TypeEqual(valueExp, e.Property.PropertyType), Expression.TypeEqual(valueExp, e.Property.PropertyType),
Expression.Return(returnTarget, Expression.Call(MethodJsonConvertSerializeObject, Expression.Return(returnTarget, Expression.Call(MethodJsonConvertSerializeObject, Expression.Convert(valueExp, typeof(object)), Expression.Constant(settings)), typeof(object)),
#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)),
elseExp); elseExp);
}); });
} }
@ -83,6 +60,5 @@ namespace FreeSql.Extensions
}); });
} }
} }
} }
} }