LambdaExpression解析(ExpressionVisitor)

Lambda表达式树解析主要通过ExpressionVisitor来实现,最终达到动态处理的效果:

ProductOrder po = new ProductOrder { OrderID = "2025", OrderDate = DateTime.Now };

            Expression<Func<ProductOrder, ProductOrderDetail, bool>> condition = (x, y) => x.OrderID == y.OrderID;

            
            
            if (condition is LambdaExpression)
            {
                if(condition.Body is BinaryExpression)
                {
                    BinaryExpression binaryExpression = condition.Body as BinaryExpression;
                    MemberExpression left = binaryExpression.Left as MemberExpression;
                    ParameterExpression leftParamExp = left.Expression as ParameterExpression;
                    //System.Linq.Expressions.ExpressionType

                    if (condition.Parameters[0].Name == leftParamExp.Name)
                    {
                        //leftParamExp
                        MemberInfo mi = left.Member;
                        PropertyInfo pi = po.GetType().GetProperty(mi.Name);
                        object ov = pi.GetValue(po);
                        //mi.get
                    }
                    //binaryExpression.Left
                }

                //BinaryExpression lambdaCondition = condition as BinaryExpression;
                //if(lambdaCondition.Parameters[0] == lambdaCondition. )
            }

  

上一篇:RSA加密---从后台到客户端实现报文加解密


下一篇:gitllab访问报错:Permission denied (publickey). 以及后续测试