Expression Trees are an abstract representation of code in a tree structure where each node of the tree represents a programming construct (conditional, assignment, method call, etc.)
Questions tagged [expression-trees]
2090 questions
1
vote
1 answer
Can't get operator overloading to work with Linq Expression Trees
I am creating Linq expression trees from F# that operates on a custom datatype I have. The type is a very simple discriminated union that has the usual arithmetic operators overloaded. But for some reason I cannot create arithmetic linq expression…

Rickard
- 1,754
- 1
- 12
- 17
1
vote
2 answers
How to select/filter against substring in a list of strings?
I have a LINQ result set I'm trying to filter in a strange and peculiar way.
List MyDomains = [Code to get list];
var x = (from a in dc.Activities
where a.Referrer != null
&& a.Referrer.Trim().Length > 0
&&…

tsilb
- 7,977
- 13
- 71
- 98
1
vote
2 answers
Expression Tree how do I capture a local variable
I'm currently working towards creating dynamic expressions and I have the following scenario, which I'd like help to achieve.
given:
public class planet {
public string name { get;set; }
}
class someTestClass {
[Test]
public void…

ermagana
- 1,090
- 6
- 11
1
vote
0 answers
Expression Trees and Joins
Expression>> attachments = t => attachmentBuilder.Populate("COMPANYNAME", t.AccountID.ToString());
var q = cxt.Accounts.Select(e => new
{
AccountID = e.AccountID,
Description =…

chugh97
- 9,602
- 25
- 89
- 136
1
vote
3 answers
Call Func<> with argument of type object
I have (for instance) a Func which I want to call as usual, except that the parameter is of type object rater than int. I only know the exact type of the Func and the argument at runtime, because the Func was created using Expression trees…
user2037593
1
vote
2 answers
Applying expression tree for List through LINQ
I Want to apply dynamic project for my List Collection. User will be selecting the columns which are noting but properties of my List. I want to get subset of columns from LINQ Statement. I want to use Dynamic LINQ. Can any1 provide how to implement…

user145610
- 2,949
- 4
- 43
- 75
1
vote
2 answers
How to pass runtime argument variable in Expression.Call?
I'm missing something trivial here. Say I have a method like this:
abstract class C
{
public static void M(Type t, params int[] i)
{
}
}
I'm learning expression trees and I need to build a delegate that calls this method with some…

nawfal
- 70,104
- 56
- 326
- 368
1
vote
2 answers
Convert Func expression to Func where T is generic constraint
I have this static function
public static object Create(Type t)
{
//unimportant
}
I don't have control on the above function above, so I cant alter it. The problem is it's not generic, so I have to cast the returned object to some type. This…

nawfal
- 70,104
- 56
- 326
- 368
1
vote
2 answers
Build LambdaExpression with custom parameter selection
Complete definition of my extension method goes first.
static IQueryable WithTicketNumbers(
this IQueryable q,
Expression> ticketSelector,
Expression> resultSelector,
…

AgentFire
- 8,944
- 8
- 43
- 90
1
vote
1 answer
Finding method call in expression tree / iterating expression tree
I need to find all calls to particular method in expression tree which can be very complex. Currently I have simple recursive code which checks for BinaryExpression, ConditionalExpression etc and of course for MethodCallExpression. It works but I…

Pol
- 5,064
- 4
- 32
- 51
1
vote
0 answers
How to build new expression to test out result of previous expression without compiling?
//IsCellDataValid Method returns bool
MethodInfo isCellDataValidMethod = this.GetType().GetMethod("IsCellDataValid", BindingFlags.NonPublic | BindingFlags.Instance);
var IsCellDataValidMethodCall = Expression.Call(ruleEngineInstance,…

Vignesh.N
- 2,618
- 2
- 25
- 33
1
vote
2 answers
Dynamically query entities from Entity Framework for association to primary Entity
I know the title wasn't the greatest, but here is what I actually want to accomplish.
I have a details view that represents Entity1 and its associations. I am capturing the property names and values in a key/value pair. I am currently using…

m4chine
- 431
- 1
- 7
- 16
1
vote
1 answer
How do I call a method from within a linq query that is retrieving from an Entity Framework model
I have the following code
return (_entities.Users.Select(profile => new ProfileUserListItemDto
{
Email = profile.Email,
FirstName = profile.FirstName,
Id = profile.Id,
…

John
- 1,403
- 3
- 19
- 31
1
vote
2 answers
Cast IEnumerable into Array in Expression Tree Func
I have an expression that has the following structure. I get it from a Expression.ArrayIndex, so I cannot change it:
Expression> expression
Afterwards I'm combining this expression with a parent one that has this…

margabit
- 2,924
- 18
- 24
1
vote
1 answer
Calling a F# function via a Linq expression tree MethodCallExpression node?
I am trying to create an expression tree containing a function call to a F# function on a certain module. However, I am missing something because the System.Linq.Expressions.Expression.Call() helper function cant find the function I'm supplying.
The…

Rickard
- 1,754
- 1
- 12
- 17