Example #1
0
        /********************************************************************************************************************/

        private DicModel StringLike(MethodCallExpression mcExpr, StringLikeEnum type)
        {
            if (mcExpr.Object == null)
            {
                return(null);
            }
            else
            {
                var objExpr     = mcExpr.Object;
                var objNodeType = mcExpr.Object.NodeType;
                if (objNodeType == ExpressionType.MemberAccess)
                {
                    var memO    = objExpr as MemberExpression;
                    var memType = objExpr.Type;
                    if (memType == typeof(string))
                    {
                        var keyTuple = GetKey(memO, OptionEnum.Like);
                        var val      = string.Empty;
                        switch (type)
                        {
                        case StringLikeEnum.Contains:
                            val = DC.VH.GetCallVal(mcExpr);
                            break;

                        case StringLikeEnum.StartsWith:
                            val = $"{DC.VH.GetCallVal(mcExpr)}%";
                            break;

                        case StringLikeEnum.EndsWith:
                            val = $"%{DC.VH.GetCallVal(mcExpr)}";
                            break;
                        }
                        return(DicHandle.CallLikeHandle(keyTuple.key, keyTuple.alias, val, keyTuple.valType));
                    }
                }
            }

            return(null);
        }
        private DicModel HandConditionCall(MethodCallExpression mcExpr)
        {
            var exprStr = mcExpr.ToString();

            if (exprStr.Contains(".Contains("))
            {
                if (mcExpr.Object == null)
                {
                    var memKey = mcExpr.Arguments[1];
                    var memVal = mcExpr.Arguments[0];
                    if (memVal.NodeType == ExpressionType.MemberAccess)
                    {
                        var keyTuple = GetKey(memKey, OptionEnum.In);
                        var val      = HandMember(memVal as MemberExpression);
                        return(DicHandle.CallInHandle(keyTuple.key, keyTuple.alias, val, keyTuple.valType));
                    }
                    else if (memVal.NodeType == ExpressionType.NewArrayInit)
                    {
                        var naExpr   = memVal as NewArrayExpression;
                        var keyTuple = GetKey(memKey, OptionEnum.In);
                        var vals     = new List <string>();
                        foreach (var exp in naExpr.Expressions)
                        {
                            vals.Add(DC.VH.GetConstantVal(exp as ConstantExpression, keyTuple.valType));
                        }
                        var val = string.Join(",", vals);
                        return(DicHandle.CallInHandle(keyTuple.key, keyTuple.alias, val, keyTuple.valType));
                    }
                }
                else
                {
                    var objExpr     = mcExpr.Object;
                    var objNodeType = mcExpr.Object.NodeType;
                    if (objNodeType == ExpressionType.MemberAccess)
                    {
                        var memO    = objExpr as MemberExpression;
                        var memType = objExpr.Type;
                        if (memType.GetInterfaces() != null &&
                            memType.GetInterfaces().Contains(typeof(IList)) &&
                            !memType.IsArray)
                        {
                            var val      = HandMember(memO);
                            var keyTuple = GetKey(mcExpr, OptionEnum.In);
                            return(DicHandle.CallInHandle(keyTuple.key, keyTuple.alias, val, keyTuple.valType));
                        }
                        else if (memType == typeof(string))
                        {
                            var keyTuple = GetKey(memO, OptionEnum.Like);
                            var val      = DC.VH.GetCallVal(mcExpr);
                            return(DicHandle.CallLikeHandle(keyTuple.key, keyTuple.alias, val, keyTuple.valType));
                        }
                    }
                    else if (objNodeType == ExpressionType.ListInit)
                    {
                        var liExpr   = objExpr as ListInitExpression;
                        var keyTuple = GetKey(mcExpr, OptionEnum.In);
                        var vals     = new List <string>();
                        foreach (var ini in liExpr.Initializers)
                        {
                            var arg = ini.Arguments[0];
                            vals.Add(DC.VH.GetConstantVal(ini.Arguments[0] as ConstantExpression, keyTuple.valType));
                        }
                        var val = string.Join(",", vals);
                        return(DicHandle.CallInHandle(keyTuple.key, keyTuple.alias, val, keyTuple.valType));
                    }
                }
            }

            return(null);
        }