LinqCompile() public static method

public static LinqCompile ( Expression expression ) : Object>.Func
expression Expression
return Object>.Func
Ejemplo n.º 1
0
        public static object FunCall(object f, object[] a, Environment environment)
        {
            // Macros are expanded and evaluated ..
            if (f is Macro)
            {
                object expansion = ((Macro)f).Call(a);
                return(Eval(expansion, environment));
            }

            // Functions are called ..
            if (f is Function)
            {
                return(((Function)f).Call(a));
            }

            // Delegates are invoked ..
            if (f is Delegate)
            {
                return(((Delegate)f).DynamicInvoke(a));
            }

            // LINQ Expressions are compiled and invoked ..
            if (f is Expression)
            {
                Func <Environment, object> ff = Compiler.LinqCompile((Expression)f);
                return(ff(environment));
            }

            throw new LSharpException(string.Format("Cant call {0} with {1}", f, a));
        }
Ejemplo n.º 2
0
        public static Object Eval(object o, Environment environment)
        {
            // If it's a delegate, just run it
            if (o is Func <Environment, object> )
            {
                Func <Environment, object> f = (Func <Environment, object>)o;
                // Execute the lambda expression.
                return(f(environment));
            }

            // If it's a LINQ Expression, then compile and run it
            if (o is Expression)
            {
                Expression expression        = (Expression)o;
                Func <Environment, object> f = Compiler.LinqCompile(expression);
                return(f(environment));
            }

            // Otherwise compile it and evaluate it again ..
            object compiledExpression = Compiler.Compile(o, environment);

            return(Eval(compiledExpression, environment));
        }