Passing an expression tree as a parameter to another expression tree in EntityDataModel
Tag : chash , By : unfool
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Option 1 Give this a try first - I just tried it with LINQ-to-SQL and it works so it should work in EF. It's not a million miles from what you had, just saying invoke e1 with the result of invoking e2: var e3 = Expression.Lambda<Func<Customer, bool>>(Expression.Invoke(e1, Expression.Invoke(e2, e2.Parameters)), e2.Parameters);
// replace parameter use anywhere in e1.Body with e2.Body
var remover = new ParameterReplaceVisitor(e2.Body);
var bb = remover.Visit(e1.Body);
// create a new lambda with our amended body but still with e2 parameters i.e. the Customer
var e3 = Expression.Lambda<Func<Customer, bool>>(bb, e2.Parameters);
public class ParameterReplaceVisitor : ExpressionVisitor
{
Expression _replace;
public ParameterReplaceVisitor(Expression replace)
{
_replace = replace;
}
protected override Expression VisitParameter(ParameterExpression node)
{
// when we encounter a parameter replace it
return _replace;
}
}
|
Transforming a Boost C++ Phoenix Expression Tree
Tag : cpp , By : thatotherguy
Date : March 29 2020, 07:55 AM
I hope this helps . In the Boost Phoenix article, "Transforming the Expression Tree", here, a set of specialisations of a custom invert_actions class, are used to invert binary arithmetic expressions. For example a+b becomes a-b; a*b becomes a/b; and vice versa for both. , This is how you do it with straight Proto: #include <iostream>
#include <boost/phoenix.hpp>
#include <boost/proto/proto.hpp>
namespace proto = boost::proto;
using namespace boost::phoenix;
using namespace arg_names;
struct invrt:
proto::or_<
proto::when<
// Turn plus nodes into minus
proto::plus<proto::_, proto::_>,
proto::functional::make_expr<proto::tag::minus>(
invrt(proto::_left), invrt(proto::_right)
)
>,
proto::otherwise<
// This recurses on children, transforming them with invrt
proto::nary_expr<proto::_, proto::vararg<invrt> >
>
>
{};
int main(int argc, char *argv[])
{
auto f = invrt()(_1+_1&_2);
proto::display_expr(f);
std::cout << f(1,2) << std::endl;
return 0;
}
#include <iostream>
#include <boost/phoenix.hpp>
#include <boost/proto/proto.hpp>
using namespace boost;
using namespace proto;
using namespace phoenix;
using namespace arg_names;
struct invrt {
template <typename Rule>
struct when :
// NOTE!!! recursively transform children and reassemble
nary_expr<_, vararg<proto::when<_, evaluator(_, _context)> > >
{};
};
template <>
struct invrt::when<rule::plus> :
proto::call<
proto::functional::make_expr<proto::tag::minus>(
evaluator(_left, _context), evaluator(_right, _context)
)
>
{};
int main()
{
auto f = phoenix::eval( _1+_1&_2 , make_context(make_env(), invrt()) );
display_expr(f);
std::cout << f(1,2) << std::endl; // Prints 0. Huzzah!
}
|
Finding method call in expression tree / iterating expression tree
Tag : chash , By : GunnarHafdal
Date : March 29 2020, 07:55 AM
|
Transforming a tree back to JSON using tree-model-js
Date : March 29 2020, 07:55 AM
This might help you Is there perhaps a way in which you can convert a TreeModel to a JSON string. That way it can be stored and then later recreated using tree.parse()? , Use JSON.stringify(root.model) instead.
|
Transforming tree recursively in JS/ES6
Date : March 29 2020, 07:55 AM
Any of those help You could take a recursive approach and iterate all keys and build new objects and take either the array or take the object for the next recursive call. function getParts(object) {
return Array.isArray(object)
? object
: Object.keys(object).map(function (k) {
return { name: k, children: getParts(object[k]) };
});
}
var data = { Parent: { Child1: ["toy1"], Child2: { Nephew: ["toy2", "toy3"] } } },
result = { name: 'root', children: getParts(data) };
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
|