ConvertExpression() public method

Converts the provided expression to the given type. The expression is safe to evaluate multiple times.
public ConvertExpression ( Expression expr, Type toType, ConversionResultKind kind, Microsoft.Scripting.Actions.Calls.OverloadResolverFactory resolverFactory ) : Expression
expr Expression
toType System.Type
kind ConversionResultKind
resolverFactory Microsoft.Scripting.Actions.Calls.OverloadResolverFactory
return Expression
Esempio n. 1
0
        public Expression MakeReturn(ActionBinder binder, Expression expr)
        {
            // we create a temporary here so that ConvertExpression doesn't need to (because it has no way to declare locals).
            if (expr.Type != typeof(void))
            {
                ParameterExpression variable = GetTemporary(expr.Type, "$retVal");
                Expression          conv     = binder.ConvertExpression(variable, ReturnType, ConversionResultKind.ExplicitCast, Context);
                if (conv == variable)
                {
                    return(MakeReturn(expr));
                }

                return(MakeReturn(Ast.Block(Ast.Assign(variable, expr), conv)));
            }
            return(MakeReturn(binder.ConvertExpression(expr, ReturnType, ConversionResultKind.ExplicitCast, Context)));
        }
Esempio n. 2
0
        public Statement MakeReturn(ActionBinder binder, Expression expr)
        {
            // we create a temporary here so that ConvertExpression doesn't need to (because it has no way to declare locals).
            if (expr.Type != typeof(void))
            {
                Variable   variable = GetTemporary(expr.Type, "$retVal");
                Expression read     = Ast.ReadDefined(variable);
                Expression conv     = binder.ConvertExpression(read, ReturnType);
                if (conv == read)
                {
                    return(Ast.Return(expr));
                }

                return(Ast.Return(Ast.Comma(Ast.Assign(variable, expr), conv)));
            }
            return(Ast.Return(binder.ConvertExpression(expr, ReturnType)));
        }
Esempio n. 3
0
        public Expression MakeReturn(ActionBinder binder, Expression expr) {
            // we create a temporary here so that ConvertExpression doesn't need to (because it has no way to declare locals).
            if (expr.Type != typeof(void)) {
                ParameterExpression variable = GetTemporary(expr.Type, "$retVal");
                Expression conv = binder.ConvertExpression(variable, ReturnType, ConversionResultKind.ExplicitCast, Context);
                if (conv == variable) return MakeReturn(expr);

                return MakeReturn(Ast.Block(Ast.Assign(variable, expr), conv));
            }
            return MakeReturn(binder.ConvertExpression(expr, ReturnType, ConversionResultKind.ExplicitCast, Context));
        }
Esempio n. 4
0
        public Statement MakeReturn(ActionBinder binder, Expression expr) {
            // we create a temporary here so that ConvertExpression doesn't need to (because it has no way to declare locals).
            if (expr.Type != typeof(void)) {
                Variable variable = GetTemporary(expr.Type, "$retVal");
                Expression read = Ast.ReadDefined(variable);
                Expression conv = binder.ConvertExpression(read, ReturnType);
                if (conv == read) return Ast.Return(expr);

                return Ast.Return(Ast.Comma(Ast.Assign(variable, expr), conv));
            }
            return Ast.Return(binder.ConvertExpression(expr, ReturnType));
        }