expression-trees

Creating expression tree for accessing a Generic type's property

岁酱吖の 提交于 2020-06-10 02:53:29
问题 I need to write a generic method which takes the instance of the generic type and the property name in string format and return an Expression tree I need to convert a simple lambda expression a => a.SomePropertyName where a is generic type which will have a property by the name SomePropertyName I know that we can get the property information using the following reflection code System.Reflection.PropertyInfo propInfo = a.GetType().GetProperty("SomePropertyName"); This might be very simple, but

How can I build logic upon supplied logic in a LINQ-to-Entities Where expression?

大憨熊 提交于 2020-05-28 12:05:12
问题 I often come across, in LINQ for Entity Framework, a pattern where I add a .Where clause if a string value is specified, like: IQueryable<Foo> query = Foos.AsQueryable() if (!string.IsNullOrWhitespace(nameFilter)) query = query.Where(x => x.Name == name); if (!string.IsNullOrWhitespace(addressFilter) != null) query = query.Where(x => x.Address == addressFilter ); if (!string.IsNullOrWhitespace(cityFilter) != null) query = query.Where(x => x.City == cityFilter ); // ... I wanted to clean this

Why would I want to use an ExpressionVisitor?

a 夏天 提交于 2020-05-09 19:33:22
问题 I know from the MSDN's article about How to: Modify Expression Trees what an ExpressionVisitor is supposed to do. It should modify expressions. Their example is however pretty unrealistic so I was wondering why would I need it? Could you name some real-world cases where it would make sense to modify an expression tree? Or, why does it have to be modified at all? From what to what? It has also many overloads for visiting all kinds of expressions. How do I know when I should use any of them and

Why would I want to use an ExpressionVisitor?

冷暖自知 提交于 2020-05-09 19:31:13
问题 I know from the MSDN's article about How to: Modify Expression Trees what an ExpressionVisitor is supposed to do. It should modify expressions. Their example is however pretty unrealistic so I was wondering why would I need it? Could you name some real-world cases where it would make sense to modify an expression tree? Or, why does it have to be modified at all? From what to what? It has also many overloads for visiting all kinds of expressions. How do I know when I should use any of them and

Why would I want to use an ExpressionVisitor?

我的梦境 提交于 2020-05-09 19:30:00
问题 I know from the MSDN's article about How to: Modify Expression Trees what an ExpressionVisitor is supposed to do. It should modify expressions. Their example is however pretty unrealistic so I was wondering why would I need it? Could you name some real-world cases where it would make sense to modify an expression tree? Or, why does it have to be modified at all? From what to what? It has also many overloads for visiting all kinds of expressions. How do I know when I should use any of them and

Why can't I create the same Expression Tree manually that my straight lambda produces

烂漫一生 提交于 2020-04-09 19:04:18
问题 I've gone through and beat my head against the wall for a while now searched on various phrases and keywords but I cannot find anything close to an answer so i'm hoping someone here can shed some light. Basically I'm working on diving pretty deep into manipulating, creating, and modifying Expression Trees in C# 4.0 I came across an odd anomaly I cannot make sense of if I write something like this Expression<Func<string,string>> InsertAString = (Insert) => "This " + (Insert == "" ? "" : Insert