expression-trees

force Expression<> to evaluate local variables

本秂侑毒 提交于 2020-01-02 05:33:11
问题 I have something like this in LinqPad void Main() { var t1 = DateTimeOffset.Parse("10/1/2012"); int? n1 = 1; Expression<Func<Sample,bool>> x1 = ud => (ud.Date == t1 && ud.Number == n1); x1.ToString().Dump(); } class Sample { public int? Number{set;get;} public DateTimeOffset Date{set;get;} } it outputs ud => ((ud.Date == value(UserQuery+<>c_ DisplayClass0).t1) AndAlso (ud.Number == value(UserQuery+<>c _DisplayClass0).n1)) is there any possible way to keep the variables but have it output

Expression tree for String.IndexOf method

旧巷老猫 提交于 2020-01-02 02:28:08
问题 How should I construct Expression tree for string.IndexOf("substring", StringComparison.OrdinalIgnoreCase) ? I can get it working without the second argument: StringComparison.OrdinalIgnoreCase . These are my attempts so far: var methodCall = typeof (string).GetMethod("IndexOf", new[] {typeof (string)}); Expression[] parms = new Expression[]{right, Expression.Constant("StringComparison.OrdinalIgnoreCase", typeof (Enum))}; var exp = Expression.Call(left, methodCall, parms); return exp; Also

Are LINQ expression trees proper trees?

一个人想着一个人 提交于 2020-01-01 23:13:15
问题 Are LINQ expression trees proper trees, as in, graphs (directed or not, wikipedia does not seem too agree) without cycles? What is the root of an expression tree from the following C# expression? (string s) => s.Length The expression tree looks like this, with "->" denoting the name of the property of the node the other node is accessible through. ->Parameters[0] Lambda---------Parameter(string s) \ / \->Body /->Expression \ / Member(Length) When using ExpressionVisitor to visit the

Parse Math Expression in PHP

萝らか妹 提交于 2020-01-01 19:56:17
问题 I'm currently trying to parse math expression into expression tree. But I'm stuck on the stage where I need to implement functions and negates. I don't understand logic to do it using Shunting-Yard algorithm. What I currently want to do is to support Negates, like -(x+5) Function calls, like min(x,y) Power just after function name, like cos^2(x) Implicit multiplication, like 2x is same as 2*x Scientific notation Constants e and pi Can somebody tell me hints how to implement this? 回答1: An

Parse Math Expression in PHP

喜夏-厌秋 提交于 2020-01-01 19:55:18
问题 I'm currently trying to parse math expression into expression tree. But I'm stuck on the stage where I need to implement functions and negates. I don't understand logic to do it using Shunting-Yard algorithm. What I currently want to do is to support Negates, like -(x+5) Function calls, like min(x,y) Power just after function name, like cos^2(x) Implicit multiplication, like 2x is same as 2*x Scientific notation Constants e and pi Can somebody tell me hints how to implement this? 回答1: An

Is reflection used when retrieving information from a linq expression?

丶灬走出姿态 提交于 2020-01-01 19:23:11
问题 I have the following extension method: public static string ToPropertyName<T,E>(this Expression<Func<E, T>> propertyExpression) { if (propertyExpression == null) return null; string propName; MemberExpression propRef = (propertyExpression.Body as MemberExpression); UnaryExpression propVal = null; // -- handle ref types if (propRef != null) propName = propRef.Member.Name; else { // -- handle value types propVal = propertyExpression.Body as UnaryExpression; if (propVal == null) throw new

Generic expression for where clause - “The LINQ expression node type 'Invoke' is not supported in LINQ to Entities.”

爷,独闯天下 提交于 2020-01-01 10:50:54
问题 I am trying to write a really generic way to load EF entities in batches, using the Contains method to generate a SQL IN statement. I've got it working if I pass the entire expression in, but when I try to build the expression dynamically, I am getting a "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities." So I know this means that EF thinks I'm calling an arbitrary method and it can't translate it into SQL, but I can't figure out how to get it to understand the

Expression trees - unnecessary conversion to int32

↘锁芯ラ 提交于 2020-01-01 08:21:23
问题 Expression trees seem to build an unnecessary conversion when working with bytes and shorts, they convert both sides (in binary expressions for instance) to int32. This is an issue in some Linq providers that I've seen, each has to peel this redundant layer to get to the original expression. (NHibernate doesn't remove this layer and creates an awful CAST in the SQL query). // no conversion Console.WriteLine((Expression<Func<int, int, bool>>) ((s, s1) => s == s1)); // converts to int32 Console

Expressions breaking code when compiled using VS2015 Update 1

余生长醉 提交于 2020-01-01 03:58:07
问题 After installing Visual Studio 2015 Update 1 on my machine I saw that some of my unit tests failed. After doing some investigation I was able to reduce the problem to this line of code: Expression<Func<GameObject, bool>> expression = t => t.X == 0 && t.Y == 0 && t.GameObjectType == GameObjectType.WindMill; When hovering over the expression variable the results were different in the versions of Visual Studio: VS 2015: VS 2015 Update 1: The logic that was doing the comparison for the enums

Need guidance towards evaluative boolean logic tree

我与影子孤独终老i 提交于 2019-12-31 17:45:56
问题 I can't seem to find a pointer in the right direction, I am not even sure what the terms are that I should be researching but countless hours of googling seem to be spinning me in circles, so hopefully the collective hive of intelligence of Stack Overflow can help. The problem is this, I need a way to filter data in what I can only call a compound logic tree. Currently the system implements a simple AND filtering system. For example, lets say we have a dataset of people. You add a bunch of