[#96]优化代码去掉Compile.DynamicInvoke
BIN
Logo/favicon.ico
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
After Width: | Height: | Size: 252 KiB |
BIN
Logo/logo.png
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 17 KiB |
3944
Logo/logo.svg
Before Width: | Height: | Size: 297 KiB After Width: | Height: | Size: 22 KiB |
|
@ -1,9 +1,9 @@
|
||||||
:start
|
:start
|
||||||
::定义版本
|
::定义版本
|
||||||
set EFCORE2=2.4.0.03
|
set EFCORE2=2.4.0.04
|
||||||
set EFCORE3=3.4.0.03
|
set EFCORE3=3.4.0.04
|
||||||
set EFCORE5=5.4.0.03
|
set EFCORE5=5.4.0.04
|
||||||
set EFCORE6=6.4.0.03
|
set EFCORE6=6.4.0.04
|
||||||
|
|
||||||
::删除所有bin与obj下的文件
|
::删除所有bin与obj下的文件
|
||||||
@echo off
|
@echo off
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace ShardingCore.Extensions
|
namespace ShardingCore.Extensions
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* @Author: xjm
|
* @Author: xjm
|
||||||
* @Description:
|
* @Description:
|
||||||
* @Date: Saturday, 14 November 2020 22:06:21
|
* @Date: Saturday, 14 November 2020 22:06:21
|
||||||
* @Email: 326308290@qq.com
|
* @Email: 326308290@qq.com
|
||||||
*/
|
*/
|
||||||
public static class ExpressionExtension
|
public static class ExpressionExtension
|
||||||
{
|
{
|
||||||
public static void SetPropertyValue<T>(this T t, string name, object value)
|
public static void SetPropertyValue<T>(this T t, string name, object value)
|
||||||
|
|
|
@ -153,19 +153,31 @@ namespace ShardingCore.Core.Internal.Visitors
|
||||||
);
|
);
|
||||||
|
|
||||||
case ListInitExpression e when e.NewExpression.Arguments.Count() == 0:
|
case ListInitExpression e when e.NewExpression.Arguments.Count() == 0:
|
||||||
var collection = e.NewExpression.Constructor.Invoke(new object[0]);
|
|
||||||
foreach (var i in e.Initializers)
|
|
||||||
{
|
{
|
||||||
i.AddMethod.Invoke(
|
var collection = e.NewExpression.Constructor.Invoke(new object[0]);
|
||||||
collection,
|
foreach (var i in e.Initializers)
|
||||||
i.Arguments
|
{
|
||||||
.Select(
|
i.AddMethod.Invoke(
|
||||||
a => GetShardingKeyValue(a)
|
collection,
|
||||||
)
|
i.Arguments
|
||||||
.ToArray()
|
.Select(
|
||||||
);
|
a => GetShardingKeyValue(a)
|
||||||
|
)
|
||||||
|
.ToArray()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return collection;
|
||||||
}
|
}
|
||||||
return collection;
|
case NewArrayExpression e when e.NodeType == ExpressionType.NewArrayInit && e.Expressions.Count > 0:
|
||||||
|
{
|
||||||
|
var collection = new List<object>(e.Expressions.Count);
|
||||||
|
foreach (var arrayItemExpression in e.Expressions)
|
||||||
|
{
|
||||||
|
collection.Add(GetShardingKeyValue(arrayItemExpression));
|
||||||
|
}
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
case MethodCallExpression e:
|
case MethodCallExpression e:
|
||||||
return e.Method.Invoke(
|
return e.Method.Invoke(
|
||||||
|
@ -317,20 +329,20 @@ namespace ShardingCore.Core.Internal.Visitors
|
||||||
{
|
{
|
||||||
if (methodCallExpression.Object is MemberExpression member1Expression)
|
if (methodCallExpression.Object is MemberExpression member1Expression)
|
||||||
{
|
{
|
||||||
arrayObject = Expression.Lambda(member1Expression).Compile().DynamicInvoke();
|
arrayObject = GetShardingKeyValue(member1Expression);
|
||||||
}
|
}
|
||||||
else if (methodCallExpression.Object is ListInitExpression member2Expression)
|
else if (methodCallExpression.Object is ListInitExpression member2Expression)
|
||||||
{
|
{
|
||||||
arrayObject = Expression.Lambda(member2Expression).Compile().DynamicInvoke();
|
arrayObject = GetShardingKeyValue(member2Expression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (methodCallExpression.Arguments[0] is MemberExpression member2Expression)
|
else if (methodCallExpression.Arguments[0] is MemberExpression member2Expression)
|
||||||
{
|
{
|
||||||
arrayObject = Expression.Lambda(member2Expression).Compile().DynamicInvoke();
|
arrayObject = GetShardingKeyValue(member2Expression);
|
||||||
}
|
}
|
||||||
else if (methodCallExpression.Arguments[0] is NewArrayExpression member3Expression)
|
else if (methodCallExpression.Arguments[0] is NewArrayExpression member3Expression)
|
||||||
{
|
{
|
||||||
arrayObject = Expression.Lambda(member3Expression).Compile().DynamicInvoke();
|
arrayObject = GetShardingKeyValue(member3Expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arrayObject != null)
|
if (arrayObject != null)
|
||||||
|
@ -413,6 +425,7 @@ namespace ShardingCore.Core.Internal.Visitors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//var shardingKeyValue = GetShardingKeyValue(methodCallExpression);
|
||||||
return x => true;
|
return x => true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,9 +442,8 @@ namespace ShardingCore.Core.Internal.Visitors
|
||||||
|
|
||||||
if (binaryExpression.Left is UnaryExpression unaryExpression)
|
if (binaryExpression.Left is UnaryExpression unaryExpression)
|
||||||
left = Resolve(unaryExpression);
|
left = Resolve(unaryExpression);
|
||||||
|
if (binaryExpression.Right is BinaryExpression binaryExpression2)
|
||||||
if (binaryExpression.Right is BinaryExpression)
|
right = ParseGetWhere(binaryExpression2);
|
||||||
right = ParseGetWhere(binaryExpression.Right as BinaryExpression);
|
|
||||||
|
|
||||||
//组合
|
//组合
|
||||||
if (binaryExpression.NodeType == ExpressionType.AndAlso)
|
if (binaryExpression.NodeType == ExpressionType.AndAlso)
|
||||||
|
|
|
@ -488,10 +488,25 @@ namespace ShardingCore.Test
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ToList_Id_Not_Eq_Test()
|
public async Task ToList_Id_Not_Eq_Test()
|
||||||
{
|
{
|
||||||
|
var methodValue = new MethodValue(){AA = "7"};
|
||||||
|
var mods123 = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Id== methodValue.GetAa()).FirstOrDefaultAsync();
|
||||||
|
Assert.NotNull(mods123);
|
||||||
|
Assert.Equal(mods123.Id,"7");
|
||||||
|
var mods12 = await _virtualDbContext.Set<SysUserMod>().Where(o => new List<string>{"3","4"}.Contains(o.Id) ).ToListAsync();
|
||||||
|
Assert.Contains(mods12, o => o.Id == "3"||o.Id=="4");
|
||||||
var mods = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Id != "3").ToListAsync();
|
var mods = await _virtualDbContext.Set<SysUserMod>().Where(o => o.Id != "3").ToListAsync();
|
||||||
Assert.Equal(999, mods.Count);
|
Assert.Equal(999, mods.Count);
|
||||||
Assert.DoesNotContain(mods, o => o.Id == "3");
|
Assert.DoesNotContain(mods, o => o.Id == "3");
|
||||||
}
|
}
|
||||||
|
public class MethodValue
|
||||||
|
{
|
||||||
|
public string AA { get; set; }
|
||||||
|
|
||||||
|
public string GetAa()
|
||||||
|
{
|
||||||
|
return AA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ToList_Id_Not_Eq_Skip_Test()
|
public async Task ToList_Id_Not_Eq_Skip_Test()
|
||||||
|
|