tagged [expression-trees]

Why can't an expression tree contain a named argument specification?

Why can't an expression tree contain a named argument specification? Using AutoMapper, I hit a place where a named argument would've fit very nicely: But the compiler yelled at me: > An expression tre...

12 Apr at 21:3

How to create LINQ Expression Tree to select an anonymous type

How to create LINQ Expression Tree to select an anonymous type I would like to generate the following select statement dynamically using expression trees: I have worked out how to generate ``` var v =...

Accessing indexer from expression tree

Accessing indexer from expression tree I am working on a filtering function. The filter will be an expression tree build by an user. There will be about 30 fields the user can use for filtering. I thi...

14 Feb at 16:58

Expression of type 'System.DateTime' cannot be used for return type 'System.Object'

Expression of type 'System.DateTime' cannot be used for return type 'System.Object' I've created an expression that I'm using for sorting which works fine, until I hit a `DateTime` field, where I get ...

23 Jan at 16:32

Getting argument values of MethodCallExpression

Getting argument values of MethodCallExpression How can I get the arguments values of a MethodCallExpression? Today I do this way, but isn´t fast enough: This method get values from a Expression, but

25 Feb at 09:28

What are some examples of MemberBinding LINQ expressions?

What are some examples of MemberBinding LINQ expressions? There are three possibilities, but I can't find examples: 1. System.Linq.Expressions.MemberAssignment 2. System.Linq.Expressions.MemberListBin...

8 Dec at 23:47

variable '' of type '' referenced from scope '', but it is not defined

variable '' of type '' referenced from scope '', but it is not defined Well, the following code is self-explaining; I want to combine two expressions into one using `And` operator. The last line cause...

6 Apr at 20:35

Caching Compiled Expression tree

Caching Compiled Expression tree How to efficiently cache methods compiled from an expression tree ? ``` public void SomeToStringCalls() { ToString(i => (i + 1).ToString(), 1); ToString(i => (i + ...

27 Aug at 14:46

How to get a value out of a Span<T> with Linq expression trees?

How to get a value out of a Span with Linq expression trees? I would like to use Linq expression trees to call the indexer of a `Span`. The code looks like: ``` var spanGetter = typeof(Span) .MakeGe...

31 Aug at 10:18

Access the value of a member expression

Access the value of a member expression If i have a product. and i have the following linq query. In an IQueryable provider, I get a MemberExpression back for the p.Price which contains a Constant Exp...

11 Apr at 12:10

"The binary operator Add is not defined for the types 'System.String' and 'System.String'." -- Really?

"The binary operator Add is not defined for the types 'System.String' and 'System.String'." -- Really? When trying to run the following code: ``` Expression> stringExpression = Expression.Lambda>( ...

11 Aug at 14:9

Expressions static method requires null instance non-static method requires non-null instance

Expressions static method requires null instance non-static method requires non-null instance I'm new to using Expressions and am getting the following error: > System.ArgumentException : Static metho...

5 Jan at 18:45

Serialize expression tree

Serialize expression tree I'm doing a distributed system in c# and have encountered a barrier. I need to be able to serialize Predicate with type ``` Predicate> p = (entities => entities.OfType().Coun...

Generate EF orderby expression by string

Generate EF orderby expression by string I want to generate expression by string parameter,some code like: then call it: ``` _c

Error in C#: "an expression tree may not contain a base access" - why not?

Error in C#: "an expression tree may not contain a base access" - why not? I was calling a method that accepts `Expression>`. As part of the expression I was passing: The compiler gave me an error tha...

8 Mar at 19:40

Performance of expression trees

Performance of expression trees My current understanding is that 'hard coded' code like this: will always perform better than expression tree code like this: ``` Expression> add = (x, y) => x + y; var...

13 May at 18:13

Creating expression tree for accessing a Generic type's property

Creating expression tree for accessing a Generic type's property 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 Expr...

24 Jan at 11:45

Create an Action<T> to "set" a property, when I am provided with the LINQ Expression for the "get"

Create an Action to "set" a property, when I am provided with the LINQ Expression for the "get" I'd like to be able to generate a compiled expression to set a property, given the lambda expression tha...

4 Jan at 17:29

Evaluate C# expression inside another expression

Evaluate C# expression inside another expression I want to use an expression in another one: This will not work when sent to LINQ to SQL because f.Compile() is unknown to SQL. How do you evaluate

8 Aug at 04:52

Internal .NET Framework Data Provider error 1025

Internal .NET Framework Data Provider error 1025 this query throws "Internal .NET Framework Data Provider error 1025" exception but the query below does not. ``` query.Select(o => new {

How do I create an expression tree to represent 'String.Contains("term")' in C#?

How do I create an expression tree to represent 'String.Contains("term")' in C#? I am just getting started with expression trees so I hope this makes sense. I am trying to create an expression tree to...

10 Nov at 18:11

Lambda Expression Tree Parsing

Lambda Expression Tree Parsing I am trying to use Lambda Expressions in a project to map to a third party query API. So, I'm parsing the Expression tree by hand. If I pass in a lambda expression like:...

15 Jul at 23:1

How do I apply OrderBy on an IQueryable using a string column name within a generic extension method?

How do I apply OrderBy on an IQueryable using a string column name within a generic extension method? ``` public static IQueryable ApplySortFilter(this IQueryable query, string columnName) where T : ...

Parsing and Translating Java 8 lambda expressions

Parsing and Translating Java 8 lambda expressions In C# you can enclose a lambda expression in an expression tree object and then possibly [parse it](http://msdn.microsoft.com/en-us/library/bb397951.a...

How to Combine two lambdas

How to Combine two lambdas > [combining two lamba expressions in c#](https://stackoverflow.com/questions/1717444/combining-two-lamba-expressions-in-c) I have two following expressions: Now I need to...

23 May at 12:2