Пример #1
0
        protected virtual void VisitNew(NewExpression nex, SqlVistorFlag flag)
        {
            for (var i = 0; i < nex.Members.Count; i++)
            {
                var arg    = nex.Arguments[i];
                var member = nex.Members[i];

                flag.Append(flag.GetColName(member.Name)).Append("=");
                VisitRight(arg, flag);
            }
        }
Пример #2
0
        protected virtual void VisitMember(MemberExpression exp, SqlVistorFlag flag)
        {
            if (exp.Expression != null &&
                exp.Expression.NodeType == ExpressionType.Parameter)
            {
                if (flag.IsRight && flag.VistorType == SqlVistorType.Update)
                {
                    var proParaName = flag.GetParaName(exp.Member.Name);
                    flag.Append(proParaName, true);

                    AddMemberProperty(proParaName, exp.Member.Name);
                }
                else
                {
                    if (exp.Member.DeclaringType.GetTypeInfo().IsGenericType &&
                        exp.Member.DeclaringType.GetGenericTypeDefinition() == typeof(Nullable <>))
                    {
                        if (exp.Member.Name == "Value")
                        {
                            Visit(exp.Expression, flag);
                        }

                        if (exp.Member.Name != "HasValue")
                        {
                            return;
                        }

                        var doesNotEqualNull = Expression.MakeBinary(ExpressionType.NotEqual, exp.Expression,
                                                                     Expression.Constant(null));
                        Visit(doesNotEqualNull, flag);
                    }
                    else
                    {
                        flag.Append(flag.GetColName(exp.Member.Name), true);
                    }
                }
            }
            else
            {
                var value = Expression.Lambda(exp).Compile().DynamicInvoke();
                Visit(Expression.Constant(value), flag);
            }
        }