Skip to content

Commit

Permalink
fix code.
Browse files Browse the repository at this point in the history
  • Loading branch information
shuxinqin committed Mar 22, 2019
1 parent 0b172e1 commit 1da89e3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/Chloe/Core/Visitors/ExpressionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,42 @@ protected override object VisitNewArray(NewArrayExpression exp)

return arr;
}
protected override object VisitMemberInit(MemberInitExpression exp)
{
object instance = this.Visit(exp.NewExpression);

for (int i = 0; i < exp.Bindings.Count; i++)
{
MemberBinding binding = exp.Bindings[i];

if (binding.BindingType != MemberBindingType.Assignment)
{
throw new NotSupportedException();
}

MemberAssignment memberAssignment = (MemberAssignment)binding;
MemberInfo member = memberAssignment.Member;

member.SetMemberValue(instance, this.Visit(memberAssignment.Expression));
}

return instance;
}
protected override object VisitListInit(ListInitExpression exp)
{
object instance = this.Visit(exp.NewExpression);

for (int i = 0; i < exp.Initializers.Count; i++)
{
ElementInit initializer = exp.Initializers[i];

foreach (Expression argument in initializer.Arguments)
{
initializer.AddMethod.Invoke(instance, this.Visit(argument));
}
}

return instance;
}
}
}
5 changes: 5 additions & 0 deletions src/Chloe/Core/Visitors/ExpressionVisitorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ protected override DbExpression VisitNewArray(NewArrayExpression exp)
object arr = ExpressionEvaluator.Evaluate(exp);
return this.Visit(ExpressionExtension.MakeWrapperAccess(arr, exp.Type));
}
protected override DbExpression VisitListInit(ListInitExpression exp)
{
object list = ExpressionEvaluator.Evaluate(exp);
return this.Visit(ExpressionExtension.MakeWrapperAccess(list, exp.Type));
}

// 处理 a.XX==XXX 其中 a.XX.Type 为 bool
DbExpression VisitBinary_Equal_Boolean(BinaryExpression exp)
Expand Down
5 changes: 5 additions & 0 deletions src/Chloe/Extensions/ReflectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public static object GetMemberValue(this MemberInfo propertyOrField, object obj)
throw new ArgumentException();
}

public static object Invoke(this MethodInfo method, object obj, params object[] parameters)
{
return method.Invoke(obj, parameters == null ? new object[0] : parameters.ToArray());
}

public static MemberInfo AsReflectedMemberOf(this MemberInfo propertyOrField, Type type)
{
if (propertyOrField.ReflectedType != type)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/Chloe.Extension.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<iconUrl>http://images.cnblogs.com/cnblogs_com/so9527/860154/o_ORMicon.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Extension for Chloe.ORM</description>
<copyright>Copyright 2016-2018</copyright>
<copyright>Copyright 2016-2019</copyright>
<tags>Chloe,ORM,Data</tags>

<dependencies>
Expand Down

0 comments on commit 1da89e3

Please sign in to comment.