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

2090 questions
1
vote
2 answers

Using a local variable in an expression tree

I have this LINQ Expression that finds all the historical changes to a given customer's CreditBalance: var history = GetHistory(id); var changes = history.Where(x => history.Where(y => y.AuditId < x.AuditId) …
scourge192
  • 1,909
  • 16
  • 22
1
vote
1 answer

Expression.Or - variable 'a' of type 'Appointment' referenced from scope '', but it is not defined

I try to concate two expressions but get error mention in title on Compile method: Expression> week1 = StartDateIsBetween(lastMonday, nextSunday); Expression> week2 = EndDateIsBetween(lastMonday,…
netmajor
  • 6,507
  • 14
  • 68
  • 100
1
vote
1 answer

Deep Clone with Expression.New and Expression Trees

I have two Generated Interfaces IPerson and IAddress. However I have defined Property Interfaces which Inherit from those base Interfaces Interfaces public interface IPerson_Name : IPerson { String Name{get;set;}} public interface IPerson_Addresses…
DrSammyD
  • 880
  • 12
  • 32
1
vote
2 answers

How to build dynamic query with expression tree for PLINQ

I want to bild customized OrderBy for PLINQ, but I don't know how to. For IQueryable, use can use below code: public static class QueryableExtensions { public static IQueryable OrderBy(this IQueryable source, string sortProperty,…
lucifer lu
  • 13
  • 2
1
vote
0 answers

How to debug/print/get an overview of your run-time generated code?

I am doing some long-winded code generation at run-time using expression trees. But once I've done the Expression.Lambda(methodBody, objArg).Compile() everything is turned into a black box. I am wondering, what is the best approach and tools…
Carlo V. Dango
  • 13,322
  • 16
  • 71
  • 114
1
vote
0 answers

apply order by to an expression tree

I have an expression which was built dynamically, and I would like to apply OrderBy method but I'm struggling with this. I have a method which is supposed to append the order clause to my pre-existing expression, but as soon as I try to build an…
Daniel
  • 2,484
  • 4
  • 27
  • 35
1
vote
1 answer

How do I translate this code into an expression tree?

I have a hashing method whose operations depend on input to the function. Profiling the program has shown that too much time is spent evaluating this hash method. I want to try changing it into an expression tree, so the inner loop checks can be…
Craig Gidney
  • 17,763
  • 5
  • 68
  • 136
1
vote
1 answer

Which Expression trees to be included in a block expression

I'm confused on which expression trees need to be added to a blockexpression when wanting code to be executed. For example, if I have ConditionalExpression, that has a reference to an IsTrue and IsFalse. Do I need to include the expressions that are…
halivingston
  • 3,727
  • 4
  • 29
  • 42
1
vote
1 answer

Hooking to HttpApplication.BeginRequest with runtime generated handler causes NullReference Exception

After hooking up to an event HttpApplication.BeginRequest (and some other HttpApplication events) with a runtime generated delegate like var expr = Expression.Lambda(Expression.Empty(), new[] { …
Vikingkom
  • 21
  • 2
1
vote
2 answers

C# expression tree the right tool for the task?

My sample project is a MVC WebApi project. The standard AuthorizeAttribute takes a Roles = "" or Users = "" parameter. I didn't have a look at the implementation yet, but I don't want to either :) Can you make this a little bit more dummy proof with…
lapsus
  • 2,915
  • 2
  • 32
  • 61
1
vote
1 answer

Cast expression tree to void

Given some expression tree inner, I want to wrap it inside no-op expression of type void. Expression inner should still be evaluated, but its return type should be thrown away. How do I do it? If you are curious as to why I would want to do it, one…
Robert Važan
  • 3,399
  • 2
  • 25
  • 31
1
vote
5 answers

o => o.MethodWithParameters | is it possible to use a method in a lambda without () and parameters

i have a method that takes as a parameter an expression because I need the method string name, and I don't care about the parameters of that method, is it possible to do that ?
Omu
  • 69,856
  • 92
  • 277
  • 407
1
vote
1 answer

Create expression from reflected type

I have a method signature like this: IPostprocessComposer Without(Expression> propertyPicker) Example usage: AutoFixture.Build() .Without(p => p.ID) …
David
  • 2,551
  • 3
  • 34
  • 62
1
vote
1 answer

Dynamic Linq query on relationship with foreign key of type Guid

I'm using System.Linq.Dynamic to query an IQueryable datasource dynamically using a where-clause in a string format, like this: var result = source.Entities.Where("City = @0", new object[] { "London" }); The example above works fine. But now I want…
Andreas Zita
  • 7,232
  • 6
  • 54
  • 115
1
vote
2 answers

Set string as int constant using Expression class

I'm dynamically creating an expression tree using values provided in an XML file (i.e. I read strings). The value and the type of the member are read from this file. I'm trying to create a ConstantExpression of an integer: XElement expression =…
Andrei V
  • 7,306
  • 6
  • 44
  • 64