Skip to content

Instantly share code, notes, and snippets.

@bwatts
Created August 29, 2014 19:06
Show Gist options
  • Save bwatts/b1574c896861d8c18be0 to your computer and use it in GitHub Desktop.
Save bwatts/b1574c896861d8c18be0 to your computer and use it in GitHub Desktop.
public class FixUpSquares : ExpressionVisitor
{
protected override Expression VisitBinary(BinaryExpression node)
{
if(node.NodeType == ExpressionType.Add)
{
if(addNode.Left.NodeType == ExpressionType.Constant && addNode.Right.NodeType == ExpressionType.Constant)
{
var left = (ConstantExpression) addNode.Left;
var right = (ConstantExpression) addNode.Right;
if(EqualityComparer<object>.Default.Equals(left.Value, right.Value))
{
node = Expression.Multiply(left, Expression.Constant(2));
}
}
}
return node;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment