public override Expression Build(IEnumerable <Expression> arguments) { var engine = PythonEngine.Create(); var scope = engine.CreateScope(); var script = PythonHelper.ReturnsDecorator + Script; var scriptSource = engine.CreateScriptSourceFromString(script); scriptSource.Execute(scope); var scopeExpression = Expression.Constant(scope); var outputType = PythonHelper.GetOutputType(scope, PythonHelper.GenerateFunction); var generatorType = Expression.GetFuncType(typeof(PythonGenerator)); var generateExpression = Expression.Call( scopeExpression, "GetVariable", new[] { generatorType }, Expression.Constant(PythonHelper.GenerateFunction)); var combinatorExpression = Expression.Constant(this); return(Expression.Call(combinatorExpression, "Generate", new[] { outputType }, generateExpression)); }
public override Expression Build(IEnumerable <Expression> arguments) { var engine = PythonEngine.Create(); var scope = engine.CreateScope(); var script = PythonHelper.ReturnsDecorator + Script; var scriptSource = engine.CreateScriptSourceFromString(script); scriptSource.Execute(scope); object selectMany; var source = arguments.Single(); var observableType = source.Type.GetGenericArguments()[0]; if (PythonHelper.TryGetClass(scope, "SelectMany", out selectMany)) { var classExpression = Expression.Constant(selectMany); var opExpression = Expression.Constant(engine.Operations); var outputType = PythonHelper.GetOutputType(engine.Operations, selectMany, PythonHelper.ProcessFunction); return(Expression.Call( typeof(PythonTransform), "Process", new[] { observableType, outputType }, source, opExpression, classExpression)); } else { var outputType = PythonHelper.GetOutputType(scope, PythonHelper.ProcessFunction); var scopeExpression = Expression.Constant(scope); return(Expression.Call( typeof(PythonSelectMany), "Process", new[] { observableType, outputType }, source, scopeExpression)); } }