expression

Find and remove parameter declaration inside Expression.Block

偶尔善良 提交于 2019-12-23 01:19:03
问题 I know how to replace a parameter with ExpressionVisitor but I was wondering if there's a way to remove a parameter from a Expression.Block. Ideally I should crawl the entire Expression tree and remove the parameter every time it is declared inside a Block. Any idea how to do that with ExpressionVisitor? 回答1: A simple class to remove local variables from a BlockExpression and replace them with whatever you want. public class BlockVariableRemover : ExpressionVisitor { private readonly

Rebuild Expression

牧云@^-^@ 提交于 2019-12-23 01:13:49
问题 I have an expression like: Expression<Func<TheObject, int, bool>> myExpression = (myObj, theType) => { myObj.Prop > theType }; I need to dynamically rebuild myExpression to a new expression of type Expression<Func<TheObject, bool>> and replace “theType” parameter from the first expression with a concrete value 123 like: Expression<Func<TheObject, bool>> myNewExpression = myObj => { myObj.Prop > 123 }; How can I do that? Br Philip 回答1: With a simple expression replacer it is quite easy: This

C# how to combine two expressions into a new one?

╄→尐↘猪︶ㄣ 提交于 2019-12-22 14:51:54
问题 I have two expressions: public static Expression<Func<int, bool>> IsDivisibleByFive() { return (x) => x % 5 == 0; } and public static Expression<Func<int, bool>> StartsWithOne() { return (x) => x.ToString().StartsWith("1"); } And I want to create a new expression that applies both at once (the same expressions are used all over my code in different combinations): public static Expression<Func<int, bool>> IsValidExpression() { return (x) => IsDivisibleByFive(x) && StartsWithOne(x); } Then do:

Why this mock with Expression<Func<T,bool> is not matching?

为君一笑 提交于 2019-12-22 13:50:03
问题 i am new on mock and i am trying to do this mock example : Repository.cs public class Repository : IRepository { public List<Person> GetForExpression(Expression<Func<Person,bool>> expression ) { ... //get person from orm using expression } } PersonService.cs public class PersonService { private IRepository _repository; public PersonService(IRepository repository) { _repository = repository; } public List<Person> GetAllPersonsWith18More() { var result = _repository.GetForExpression(x => x.Age

How do you transfer the execution of a Expression created by an IQueryable object to a IEnumerable?

喜欢而已 提交于 2019-12-22 11:01:54
问题 In my code I'd like to make my repositories IQueryable. This way, the criteria for selection will be a linq expression tree. Now if I want to mock my repository in theorie this is very easy : just implement the interface of my repository (which is also a IQueryable object). My mock repository implementation would be only a in memory collection, but my question is : Do you know an easy way to implement the IQueryable interface of my mock, to transfer the query to my in-memory collection

WF. C# expressions inside of NativeActivity

≯℡__Kan透↙ 提交于 2019-12-22 10:27:27
问题 I am trying to use custom c# expression inside of NativeActivity It works fine with simple expression like Condition = new CSharpValue("1 == 1") It doesn't work with such expressions Condition = new CSharpValue("Address == null") I cannot refer to the activity's Variable or InArgument in the expression due to expression compilation error "The name 'xxxxx' does not exist in the current context" Working code var act = new ExecuteIfTrue { Condition = new CSharpValue<Boolean>("1 == 1"), Address =

Non-standard evaluation of expressions in S4 context

妖精的绣舞 提交于 2019-12-22 09:38:03
问题 This is borrowed from shiny's function exprToFunction which is used in their reactive function. Actual question How can I delay the evaluation of an expression (e.g. specified via arg expr ) in order to "capture" its content when calling a S4 method (as opposed to a standard R function)? Example Note that x_1 does not exist yet, that's why we want to delay the evaluation of expr and just "capture" its content. Function captureExpression : captureExpression <- function( expr, caller_offset = 1

Mvel iterate a list

醉酒当歌 提交于 2019-12-22 08:50:50
问题 I have this class hierarchy StudentClass .java public class StudentClass { private List<Student> studentList; public List<Student> getStudentList() { return studentList; } public void setStudentList(List<Student> studentList) { this.studentList = studentList; } } Student.java public class Student { private Child child; private int studAge; public Student(Child child, int studAge) { this.child = child; this.studAge = studAge; } public Child getChild() { return child; } public void setChild

Undefined behavior and sequence point

丶灬走出姿态 提交于 2019-12-22 08:24:45
问题 From past few days I was trying to learn about undefined behavior. Few days ago I found a c-faq link. This helps a lot to clear many confusions, but creates an another big confusion when I read the question #3.8. After my lots of efforts to understand the statement (specially second sentence); The Standard states that Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall

Implementing user-defined arithmetic functions

偶尔善良 提交于 2019-12-22 07:09:07
问题 How can I add a function (e.g., hammingweight) and use it in expressions occuring in the right-hand side is some (is)/2 goal? Could something like goal_expansion or term_expansion help here? I acknowledge that this is not a big feature, but it could increase readability of some of my Prolog programs. Writing a custom (is)/2 predicate (implementing a custom expression evaluator) is do-able, but I would like to keep runtime overhead low, as I don't want to sacrifice readability for runtime