Skip to main content

Questions tagged [expression-trees]

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.)

expression-trees
1 vote
2 answers
105 views

Compiled lambda expression leading to new delegate allocations, whereas non-expression version does not

This compiled expression tree... var param = Expression.Parameter(typeof(int)); var innerParam = Expression.Parameter(typeof(Action<int>)); var inner = Expression.Lambda(innerParam.Type, ...
Bogey's user avatar
  • 5,492
3 votes
2 answers
98 views

Expression trees - invoke lambda during loop leads to variable leaking

I have found little issue with expression trees and would like to know whether such is a bug or a feature. I have this code. The first function assigns one to a variable and returns it. static class ...
Vojtech G's user avatar
0 votes
0 answers
70 views

Creating a Lambda for LINQ from code gives error message "Parameter could not be translated"

I am attempting to build a lambda from data. The module entity has an AlgNo property of type string. I am trying to get a simple sample code to run before attempting the more advanced case. Consider ...
Tormod's user avatar
  • 4,553
0 votes
0 answers
64 views

Expression tree - how to check if element of a list fulfills specific conditions?

I'm using an Expression<Func<T, object?>> DatabaseProjection which defines what values I want to extract from T. In specific case, I will get a list of objects (string or int): ...
Michal Szura's user avatar
0 votes
1 answer
66 views

Expression.Call on array with a custom function

I have a list of items, I want ,via expression, to filter out the items using my own custom function. Something like this return Items.Where(Foo) private static bool Foo(Item item) { item.Name.Equals(&...
styx's user avatar
  • 1,902
0 votes
0 answers
43 views

Create expression trees using generic arguments which involves nested properties [duplicate]

I am trying to create a dynamic query generator, using generic arguments. For example: Expression<Func<T, bool>> CreateExpression<T>( ParameterExpression parameter, List<...
Vikneshwaran Seetharaman's user avatar
1 vote
1 answer
43 views

Accessing x levels of n-ary tree to manipulate a node and add child node with recursion

I have a problem I'm trying to solve where I can take in a variety of expression of different lengths and complexities and insert them as nodes into an n-ary (or non-binary) tree. I need to pinpoint ...
Meike Magdalena Büttner's user avatar
4 votes
3 answers
186 views

Is there no way for Csharp to write a truly static λ expression?

Language : C# .Net Version : 8.0 IDE : VS2020 / VSCode OS : Windows11 Is there no way for Csharp to write a truly static λ expression? I studied currying today and wrote a ...
黎民禹's user avatar
2 votes
2 answers
392 views

How to convert Func<T, bool> to Expression<Func<T, bool>>

I use this code but it gets an error that: Error: System.ArgumentException: Expression of type '...GreenPaperItem' cannot be used for parameter of type 'System.Runtime.CompilerServices.Closure' of ...
mz1378's user avatar
  • 2,430
0 votes
1 answer
118 views

Unable to resolve expression constants from variable

Following this post marked answer, I've copied Evaluator.cs into my project for partial evaluations to be able to resolve local variables of the expression. Regardless, it seems I'm missing something ...
Aren Devel's user avatar
1 vote
0 answers
61 views

How does .Any() access entity property when built with an expression tree?

First of all, this code works but I don't understand why it works. This question is asking why I can access a property in an expression tree when I don't think I should. Let's start by establishing ...
Matthew Peterson's user avatar
0 votes
0 answers
82 views

Expression tree to sql, Guid constants are translated to string in database and can't be read as Guid

I have a method that returns some dynamic grouping keys: private Expression<Func<T, object>> GetKeySelector<T>(Request req, Expression<Func<T, Guid>> domainKey, ... /...
sommmen's user avatar
  • 7,329
0 votes
0 answers
53 views

CS0834 - A lambda expression with a statement body cannot be converted to an expression tree [duplicate]

I am trying to create an Expression to filter the profiles by creation date here is the code private static Expression<Func<Profile, bool>> MonthsPeriodFilter = profile => { var ...
KA-Yasso's user avatar
  • 273
1 vote
1 answer
96 views

C# merge/combine expressions

With the following example classes (which could map to a database table): class Package { public string Name { get; set; } public decimal Price { get; set; } public bool Enabled { get; set;...
Parsa99's user avatar
  • 376
0 votes
2 answers
71 views

How to NULL check and do a ToLower call along with Contains call dynamically using Expression Tree in C#

I'm trying to dynamically generate the following expression x => x?.ToLower().Contains(value?.ToLower()) on my Item class. Here is my Item class: public class Item { public string? Type { get; ...
fingers10's user avatar
  • 7,649

15 30 50 per page
1
2 3 4 5
141