Skip to content

feat: map an expression even if it would change the meaning of the operation. #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

rodrigoreis
Copy link

Creates a feature to allows map an expression even if it would change the meaning of the operation.

It's avoid the following:

System.InvalidOperationException: Rewriting child expression from type to type is not allowed, because it would change the meaning of the operation. If this is intentional, override 'VisitUnary' and change it to allow this rewrite.

@BlaiseD
Copy link
Member

BlaiseD commented Aug 14, 2019

Maybe a better fix would be to just replace the VisitUnary method with:

        protected override Expression VisitUnary(UnaryExpression node)
        {
            return DoVisitUnary(Visit(node.Operand));

            Expression DoVisitUnary(Expression updated)
            {
                if (updated != node.Operand)
                    return node.Update(updated);

                return node;
            }
        }

The existing processing would them be handled by VisitLambda and VisitConstant.

@BlaiseD
Copy link
Member

BlaiseD commented Aug 14, 2019

Opened Isuue #37 to track this.

@BlaiseD
Copy link
Member

BlaiseD commented Aug 17, 2019

Closing this in favor of PR #38 - I've described the fix in earlier comments.

@BlaiseD BlaiseD closed this Aug 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants