mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
Revert "Json扩展支持JsonSerializerSettings"
This reverts commit d8f49808a831648fac77efb69ebda18cb4ca7bc1.
This commit is contained in:
parent
d8f49808a8
commit
519f82b046
@ -18,8 +18,6 @@ namespace base_entity
|
||||
{
|
||||
public int clicks { get; set; }
|
||||
public string title { get; set; }
|
||||
|
||||
public string nullvalue { get; set; }
|
||||
}
|
||||
[Table(Name = "sysconfig")]
|
||||
public class S_SysConfig<T> : BaseEntity<S_SysConfig<T>>
|
||||
@ -45,7 +43,7 @@ namespace base_entity
|
||||
.UseNoneCommandParameter(true)
|
||||
.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.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)
|
||||
.Build();
|
||||
BaseEntity.Initialization(fsql);
|
||||
@ -61,12 +59,10 @@ namespace base_entity
|
||||
|
||||
var items1 = Products.Select.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 });
|
||||
#else
|
||||
BaseEntity.Orm.UseJsonMap(new JsonSerializerSettings { NullValueHandling=NullValueHandling.Ignore });
|
||||
#endif
|
||||
new S_SysConfig<TestConfig> { Name = "testkey11", Config = new TestConfig { clicks = 11, title = "testtitle11", nullvalue = null } }.Save();
|
||||
|
||||
BaseEntity.Orm.UseJsonMap();
|
||||
|
||||
new S_SysConfig<TestConfig> { Name = "testkey11", Config = new TestConfig { clicks = 11, title = "testtitle11" } }.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();
|
||||
var testconfigs11 = S_SysConfig<TestConfig>.Select.ToList();
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0</TargetFrameworks>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
@ -13,9 +13,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">
|
||||
<DefineConstants>NETCORE30</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.BaseEntity\FreeSql.Extensions.BaseEntity.csproj" />
|
||||
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.JsonMap\FreeSql.Extensions.JsonMap.csproj" />
|
||||
|
@ -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>
|
||||
@ -29,11 +29,8 @@
|
||||
<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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user