예제 #1
0
        private DbExpression RootTranslate(TranslationContext context, Expression exp)
        {
            switch (exp.NodeType)
            {
            case ExpressionType.Call:
                var call   = (MethodCallExpression)exp;
                var method = call.Method;
                if (method.IsGenericMethod)
                {
                    method = method.GetGenericMethodDefinition();
                }
                if (UnitTypeMethods.ContainsKey(method))
                {
                    return(UnitTypeTranslate(context, exp));
                }
                else if (UnitItemTypeMethods.ContainsKey(method))
                {
                    return(UnitItemTypeMethods[method](context, call, method));
                }
                else if (ValueTypeMethods.ContainsKey(method))
                {
                    return(ValueTypeMethods[method](context, call, method));
                }
                break;

            case ExpressionType.Constant:
                return(UnitTypeTranslate(context, exp));

            default:
                return(ExpressionTranslate(context, exp));
            }
            throw new TranslateException(exp, Res.NotSupportedParseExpression);
        }
예제 #2
0
 private DbExpression ValueTypeTranslate(TranslationContext context, Expression exp)
 {
     switch (exp.NodeType)
     {
     case ExpressionType.Call:
         var call   = (MethodCallExpression)exp;
         var method = call.Method;
         if (method.IsGenericMethod)
         {
             method = method.GetGenericMethodDefinition();
         }
         if (ValueTypeMethods.TryGetValue(method, out ValueTypeTranslateMethodType action))
         {
             return(action(context, call, method));
         }
         if (method.IsDefined(typeof(DbFunctionAttribute)))
         {
             return(ScalarCustomFunctionTranslate(context, call, method));
         }
         if (RecursiveConstantTranslate(context, exp, out DbExpression result))
         {
             return(result);
         }
         break;
     }
     throw new TranslateException(exp, Res.NotSupportedExpressionParseValueType);
 }