expression

Create dynamic LINQ query expression at runtime which translates into a parameterized SQL query

蹲街弑〆低调 提交于 2020-01-02 14:30:13
问题 I want to create my custom expression for IQueryable. Sample extension method: public static IQueryable<T> GetByIntTest<T>(this IQueryable<T> qSource, Expression<Func<T, int?>> field, int? value) { if (value == null) return qSource; ConstantExpression constantExpression = Expression.Constant(value, typeof(int?)); BinaryExpression binaryExpression = Expression.Equal(field.Body, constantExpression); var predicate = Expression.Lambda<Func<T, bool>>(binaryExpression, field.Parameters); return

Converting an infix expression (with parentheses) into a binary tree

给你一囗甜甜゛ 提交于 2020-01-02 03:17:06
问题 As part of a Java assignment, I have to take an input arithmetic expression and store it in a binary tree. I have done everything necessary for the assignment except for the part where I read in the string of the expression and store it in the binary tree. I have created a class called BinaryTree. Its only field is a treenode called root. This treenode is defined as an innerclass in BinaryTree. It has 3 fields, a generic data field, and two children (left and right) that are type BinaryTree.

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

Creating a type that can be used as a Func/method

杀马特。学长 韩版系。学妹 提交于 2020-01-01 18:59:08
问题 I have been playing around with LINQ to Z3 for fun (not production use). I've ended up with this syntax as a start: var i = 123; var test2 = from t in TheormProver.NewTheorm() let f = TheormProver.Func<int, bool>() let a = TheormProver.Int let g = TheormProver.Func<bool, int>() where !f(a * 2) && g(f(g(f(4)))) == i * a && a < g(f(a)) select new { f = f.ToString(), g = g.ToString(), a, asd = "Test extra property" }; var solution = test2.Solve(); // Edited in for clarification // note that

Convert Predicate<T> to Expression<Func<T, bool>>

ⅰ亾dé卋堺 提交于 2020-01-01 09:33:14
问题 Is possible to convert a Predicate<T> to Expression<Func<T, bool>> in some way? I would like to use the next IQueryable function using the filters of the my ICollectionView: public static System.Linq.IQueryable<TSource> Where<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, bool>> predicate) Thanks 回答1: In theory it is possible to convert a delegate 'back' to an expression, because you can request the emitted IL of a delegate, which

REGEX To accept numbers separated by commas, but number range is 0-32767

我的未来我决定 提交于 2020-01-01 08:47:36
问题 I need to write a regular expression for taking input like this 23,456,22,1,32767 i.e. No commas allowed at the start or end. Spaces may come before and/or start of comma for e.g. 23, 45,56 ,67 etc. Ranges of each number should be 0-32767. Currently I am using regular expression like this [0-9]+(,[0-9]+)* . This allows for numbers separated by commas only ( not allowing spaces at all), and it does not check for the range of number. 回答1: It's probably wise to do it in two steps. First check

Generate a list of expression literals from an integer sequence

≯℡__Kan透↙ 提交于 2020-01-01 06:45:09
问题 I would like to map a sequence of integers to a sequence of expression literals in order to use the latter as tick mark labels in a plot, e.g. lbls <- lapply(-2:2, function(i) expression(i * pi)) plot(...) axis(1, at=seq(-2,2)*pi, labels=lbls) So far I've tried all variations of bquote , substitute , expression etc. that I could think of, but apparently I must have missed something. Also, the FAQ and related SO questions & answers didn't fully solve this for me. How would I do it correctly (I

ublas matrix expression tutorial/examples

徘徊边缘 提交于 2020-01-01 04:12:32
问题 I am trying to implement certain matrix operations but I am lost in the internals of ublas library. is there a resource such as tutorial or an example on how to implement new ublas matrix expressions? Thanks 回答1: Don't know if it'll help, but there's a wiki page on extending uBlas here. That expression template stuff really blows my mind. :) 回答2: My suggestion is to just template your new functions so you don't have to worry about matrix expressions or ublas internals. For example, if you

If-then-else inside a JSP expression?

风流意气都作罢 提交于 2019-12-31 13:01:30
问题 Can you do an if-then-else statement inside a JSP expression? EDIT : Specifically I was looking for a JSP solution, not a JSTL solution. But some JSTL solutions below are highly rated and are very welcome. Just please do not vote me down for a duplicate question because one has already been asked about JSTL. 回答1: In JSP EL 2.0, you can do that using the ternary operator. For instance: <option value="1" ${param.number == 1 ? 'selected' : ''}>First option</option> What it does is it checks JSP