-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add expression visitor to ignore checked expressions
- Loading branch information
1 parent
68783e1
commit ccb3833
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Linq.Expressions; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query | ||
{ | ||
public class IgnoreCheckedExpressionVisitor: ExpressionVisitor | ||
{ | ||
protected override Expression VisitBinary(BinaryExpression node) | ||
{ | ||
var visitedLeft = Visit(node.Left); | ||
var visitedRight = Visit(node.Right); | ||
|
||
var visitBinary = node.NodeType switch | ||
{ | ||
ExpressionType.AddChecked => Expression.Add(visitedLeft, visitedRight), | ||
ExpressionType.SubtractChecked => Expression.Subtract(visitedLeft, visitedRight), | ||
ExpressionType.MultiplyChecked => Expression.Multiply(visitedLeft, visitedRight), | ||
_ => base.VisitBinary(node) | ||
}; | ||
|
||
return visitBinary; | ||
} | ||
|
||
protected override Expression VisitUnary(UnaryExpression node) | ||
{ | ||
var operand = Visit(node.Operand); | ||
|
||
var visitUnary = node.NodeType switch | ||
{ | ||
ExpressionType.ConvertChecked => Expression.Convert(operand, node.Type), | ||
_ => base.VisitUnary(node) | ||
}; | ||
|
||
return visitUnary; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters