expression-trees

Solving Binary Tree

有些话、适合烂在心里 提交于 2019-12-25 08:49:40
问题 Can anyone explain how I Solve a expression Tree when I'm given x as a parameter? For example, I have the equation ((2*x)) + 4and let's say in the parameter, x = 3. This would give us 10 and the method would return this. The way I thought about doing this was to do it recursively but I can't really do it because the parameter has to be the double x. Any thoughts? Here's the code I have so far. public double evaluate(double x) throws ExpressionTreeNodeException { ExpressionTreeNode n = new

Serialize arithmetic expression-tree

泪湿孤枕 提交于 2019-12-25 08:17:06
问题 I'm doing a simple task for investigation purposes. The problem is as follows: Create an arithmetic expression with variables. Build an AST for the expression. Send it to the server (using Sockets) Calculate an result of the server side and return the results. Now I can to build a tree. This method doing it: private readonly Stack<Expression> expressionStack = new Stack<Expression>(); private readonly Stack<Symbol> operatorStack = new Stack<Symbol>(); private readonly List<string> parameters

Is it necessary to convert infix notation to postfix when creating an expression tree from it?

…衆ロ難τιáo~ 提交于 2019-12-25 06:26:43
问题 I want to create an expression tree given expression in infix form. Is it necessary to convert the expression to postfix first and then create the tree? I understand that it somehow depends on the problem itself. But assume that it is simple expression of mathematical function with unknowns and operators like: / * ^ + -. 回答1: No. If you're going to build an expression tree, then it's not necessary to convert the expression to postfix first. It will be simpler just to build the expression tree

Expression-tree to build sub-select results

自古美人都是妖i 提交于 2019-12-25 05:03:15
问题 I'm trying to build a sub-query by using expression-trees. In linq I would write something like: var single = MyTable .AsExpandable() .Select(c => new { Childs = Enumerable.Select( MyTable.VisibleChilds.Invoke(c, dbContext), cc => Convert(cfg.ChildsConfig).Invoke(dbContext, cc)) }); where the Convert is building an expression like p => new MyTableSelect { Id = p.Id, Name = p.Name } depending on the given values from the config (to only read needed data from database). but I'm struggeling with

Ambiguous call on an Action<T> where T inherits 2 interfaces having the same method signature

…衆ロ難τιáo~ 提交于 2019-12-25 04:59:20
问题 I have the following code: public class MyClass { public void MyMethod() { Action<Child> aFoo = a => a.Foo(); } } interface Parent1 { void Foo(); } interface Parent2 { void Foo(); } interface Child : Parent1, Parent2 { } However, the compiler tells me that I have an ambiguous call on aFoo . I tried to do Action<Child> aFoo = (A a) => a.Foo(); but it tells me that I cannot convert lambda expression to delegate type System.Action<Child> How do I resolve the error of ambiguity? 回答1: By casting

Invoking lambda expressions in Expression trees

流过昼夜 提交于 2019-12-25 02:58:18
问题 I have a SelectionCriteria class that I use for building Entity Framework query expressions, based on PredicateBuilder. Within its limits, it's working fine. I'd like to extend it so that it can query whether a field contains a substring. My problem is that I can't see how to build the needed expression object. My actual class supports and, or, and not, but they aren't relevant to my question. So I've simplified my example code to handle only a single binary operation: public class

Python: Expanding Complicated Tree DataStructure

让人想犯罪 __ 提交于 2019-12-25 02:04:41
问题 I am exploring a data structure which get expands to sub-elements and resolves to a final element. But I only want to store top two levels. Example: Lets say I start with New York which breaks into Bronx, Kings, New York, Queens, and Richmond as counties but then finally somehow they resolve to USA. I am not sure if this is a good example but just to make it clear here is more clear explanation of the problem. A (expands to) B,C,D -> B (expands to) K,L,M -> K resolves to Z I initially wrote

Alter Lambda Expression to go one level deeper

爷,独闯天下 提交于 2019-12-24 20:33:14
问题 Suppose I have a method like this: public void MultiDropDown<T>(Expression<Func<T, DropDownModel<DropDownItem>>> expression) { // Here i want to get more specific with the expression selector // Suppose it was passed like this: // MultiDropDown(x => x.MyDropDown); // I need to alter `expression` and go deeper: x => x.MyDropDown.Title; // And then use the new expression for other stuff... } Solution Thanks to svick ! public void MultiDropDown<T>(Expression<Func<T, DropDownModel<DropDownItem>>>

ExpressionTree method to Assign MemberInitExpression to property

假装没事ソ 提交于 2019-12-24 18:22:11
问题 I am trying to use expression trees so that I can choose to map across to a DTO using entity framework in much the same way as the Include directive works on a DbSet (part of an open sorce project implementing OData). The code below represents a test case. Expression<Func<Bar, Bar>> mapBar = b => new Bar { BarInt = b.BarInt, BarString = b.BarString }; Expression<Func<Foo, Foo>> mapFoo = f => new Foo { FooInt = f.FooInt, B = null }; Expression<Func<Foo, Foo>> target = f => new Foo { FooInt = f

Expression with dynamic class

折月煮酒 提交于 2019-12-24 17:30:01
问题 I'm trying to make Expressions work with dynamic classes that inherits DynamicObject like this: // Dynamic class defintion public class DynamicClass1 : DynamicObject { // Code here... } // Here is where I try to create where "someproperty" is untyped and the DynamicClass1 is referenced (not shown here) public static IQueryable DoStuff(this IQueryable source, string predicate, params object[] values) { LambdaExpression lambda = DynamicExpression.ParseLambda(source.ElementType, typeof(bool),