expressionvisitor

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

Find and remove parameter declaration inside Expression.Block

偶尔善良 提交于 2019-12-23 01:19:03
问题 I know how to replace a parameter with ExpressionVisitor but I was wondering if there's a way to remove a parameter from a Expression.Block. Ideally I should crawl the entire Expression tree and remove the parameter every time it is declared inside a Block. Any idea how to do that with ExpressionVisitor? 回答1: A simple class to remove local variables from a BlockExpression and replace them with whatever you want. public class BlockVariableRemover : ExpressionVisitor { private readonly

Replace parameter type in lambda expression

这一生的挚爱 提交于 2019-12-21 04:15:34
问题 I am trying to replace the parameter type in a lambda expression from one type to another. I have found other answers on stackoverflow i.e. this one but I have had no luck with them. Imagine for a second you have a domain object and a repository from which you can retrieve the domain object. however the repository has to deal with its own Data transfer objects and then map and return domain objects: ColourDto.cs public class DtoColour { public DtoColour(string name) { Name = name; } public

Replace parameter type in lambda expression

末鹿安然 提交于 2019-12-21 04:15:24
问题 I am trying to replace the parameter type in a lambda expression from one type to another. I have found other answers on stackoverflow i.e. this one but I have had no luck with them. Imagine for a second you have a domain object and a repository from which you can retrieve the domain object. however the repository has to deal with its own Data transfer objects and then map and return domain objects: ColourDto.cs public class DtoColour { public DtoColour(string name) { Name = name; } public

How to build a LambdaExpression from an existing LambdaExpression Without Compiling

試著忘記壹切 提交于 2019-12-09 12:57:45
问题 I want to combine two LambdaExpressions without compiling them. This is what it looks like if I do compile them: public Expression<Func<TContainer,bool>> CreatePredicate<TContainer,TMember>( Expression<Func<TContainer,TMember>> getMemberExpression, Expression<Func<TMember,bool>> memberPredicateExpression) { return x => memberPredicateExpression.Compile()(getMemberExpression.Compile()(x)); } That's obviously not the fastest way to get the target expression from the provided arguments. Also, it

Find and remove parameter declaration inside Expression.Block

不想你离开。 提交于 2019-12-08 13:17:26
I know how to replace a parameter with ExpressionVisitor but I was wondering if there's a way to remove a parameter from a Expression.Block. Ideally I should crawl the entire Expression tree and remove the parameter every time it is declared inside a Block. Any idea how to do that with ExpressionVisitor? A simple class to remove local variables from a BlockExpression and replace them with whatever you want. public class BlockVariableRemover : ExpressionVisitor { private readonly Dictionary<Expression, Expression> replaces = new Dictionary<Expression, Expression>(); public readonly Func

how to evaluate an Expression inside ExpressionVisitor?

不羁岁月 提交于 2019-12-06 04:21:40
问题 I need to use ExpressionVisitor to analyse an Expression before executing it. For my needs, i need to evaluate the right part of a Divide expression but i don't know how to do it. Here's a sample code that i have: internal class RulesChecker : ExpressionVisitor { private readonly object data; public RulesChecker(object data) { this.data = data; } protected override Expression VisitBinary(BinaryExpression node) { if (node.NodeType == ExpressionType.Divide) { var rightExpression = node.Right; /

How to build a LambdaExpression from an existing LambdaExpression Without Compiling

北战南征 提交于 2019-12-03 16:14:28
I want to combine two LambdaExpressions without compiling them. This is what it looks like if I do compile them: public Expression<Func<TContainer,bool>> CreatePredicate<TContainer,TMember>( Expression<Func<TContainer,TMember>> getMemberExpression, Expression<Func<TMember,bool>> memberPredicateExpression) { return x => memberPredicateExpression.Compile()(getMemberExpression.Compile()(x)); } That's obviously not the fastest way to get the target expression from the provided arguments. Also, it makes it incompatible with query providers like LINQ to SQL that do not support C# method calls. From